I'm implementing an import feature for my Android app. I wanted to let the user select files which they want to import from the external storage on their device (the downloads directory to be exact) and other online file storages such as DropBox and Google Drive.
I implemented it and tested it on an emulator and two android devices.
When I tested it on the emulator, Android Version 6.0, since it doesn't have DropBox and GoogleDrive installed, I'm seeing what I'm expecting, which is being able to select a file from the Downloads directory:
When I tested it on the Google Pixel phone, Android Version 7.1.2, everything is working as I expected. I can choose a file from the downloads directory, Google Drive as well as DropBox:
However, when I tested it on the Samsung Galaxy 4 device, Android Version 5.0.1, I'm able to select a file from both Google Drive and Dropbox, but I don't have the option to select a file from my downloads directory:
This is my code for selecting a file:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/*");
startActivityForResult(intent, GET_FILE_RESULT_CODE);
Please let me know what I can do to fix this issue. Thanks!
I ended up using ACTION_OPEN_DOCUMENT which did the trick. Now I can select file from my external storage for Android 5.0.1 as well.
However, ACTION_OPEN_DOCUMENT is only supported for API 19 and above.
So this is what I did:
if (Build.VERSION.SDK_INT >= 19) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("text/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, GET_FILE_RESULT_CODE);
}
else {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, GET_FILE_RESULT_CODE);
}
Hopefully this can help someone that runs into the same problem. Please also let me know if anyone figures out why I can't get ACTION_GET_CONTENT to select from external storage for Android 5.0.1. Thanks!