Hey Android devs! I’m new to this and need some help with file selection on older Android versions (before API 19).
I’ve got this code for choosing files:
void pickMyFile() {
Intent picker = new Intent(Intent.ACTION_GET_CONTENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
picker.setType("application/pdf|file");
} else {
picker.setType("image/*|application/pdf");
}
startActivityForResult(picker, FILE_PICK_CODE);
}
But here’s the thing: I don’t want Google Drive to show up as an option. I just want the regular file manager. Is there a way to do this with intents?
Any tips would be awesome! Thanks!
I’ve dealt with this issue before, and it can be tricky. For pre-KitKat devices, completely disabling Google Drive in file selection isn’t straightforward due to how Android handles intents.
One workaround I’ve used is to specify a more restrictive MIME type. Instead of “image/*|application/pdf”, try using just “application/pdf”. This narrows down the options and might prevent Google Drive from appearing.
Another approach is to use a third-party file picker library. I’ve had success with aFileChooser or MaterialFilePicker. They give you more control over the file selection process and can be configured to exclude cloud storage options.
Lastly, consider implementing your own file picker UI for older devices. It’s more work, but it gives you full control over what’s displayed. You can use the File API to navigate the file system directly.
Remember, each approach has trade-offs in terms of user experience and development effort. Choose what works best for your specific use case.
yo, i’ve run into this too. it’s a pain, right? one thing u could try is using ACTION_OPEN_DOCUMENT instead of ACTION_GET_CONTENT. it tends to favor local files over cloud stuff. might help keep drive outta the picture. worth a shot!
I’ve encountered similar challenges with file selection on older Android versions. One approach that’s worked for me is using the FileProvider class from the support library. It allows you to securely share files between your app and other apps without exposing Google Drive options.
To implement this, you’d need to set up a FileProvider in your AndroidManifest.xml and create a file selection method that uses it. This gives you more control over which files are accessible and can effectively bypass cloud storage options.
Keep in mind that this method requires a bit more setup, but it provides a consistent experience across different Android versions. It’s also worth noting that completely blocking Google Drive might frustrate some users who rely on it, so consider the trade-offs for your specific app requirements.