October 2018
Intermediate to advanced
464 pages
15h 17m
English
The access request is handled by the OS, not by the app. To request access, we need to call createAccessIntent(), which we do with this line of code:
Intent intent = storageVolume.createAccessIntent(Environment.DIRECTORY_MUSIC);
We call the Intent using the startActivityForResult() method, which we’ve used before. Since we are looking for a result to come back, we need to pass a unique identifier to know when the returned result callback is from our request. (The onActivityResult() callback method can receive callbacks for multiple requests.) If the request code matches our request, we then check whether the result code equals Activity.RESULT_OK, which means the user granted the permission request. We pass the result to