According to the documentation, you should use an ACTION_PICK
intent with the startActivityForResult()
method:
final int ACTION_PICK_RESULT = 0;
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("*/*");
startActivityForResult(intent, ACTION_PICK_RESULT);
You can then retrieve the file in the onActivityResult()
method of your activity.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent returnIntent) {
if (resultCode == RESULT_OK) {
Uri returnUri = returnIntent.getData();
try {
ParcelFileDescriptor pfd = getContentResolver()
.openFileDescriptor(returnUri, "r");
FileDescriptor fd = pfd.getFileDescriptor();
// TODO Do stuff with the file
}
catch (FileNotFoundException e) {
Log.e("MainActivity", "File not found.");
}
}
}
See this page for more information: Requesting a Shared File