Is there a way to remove items like "Downloads", "Pictures" or "Videos" sections from the android file picker?
I know that Google Drive for example can be removed using:
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
But how can you remove the others? I'm trying it on a Samsung device, reading through some posts I found out that there might be vendor-related configurations that you have to specify for the intent. Mine looks like this:
Intent intent = new Intent(Intent.OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.setType("*/*");
Have you tried to specify the MIME type?
Try changing this
intent.setType("*/*");
To this
intent.setType("image/*");
In this case you won't see videos and audio.
Change the MIME type according to what you need.
Related
I am facing an issue while opening the File Manager from Android apps.
I want to see only particular file only which I have specific but I am able to see other file also but it is not highlight it is been grey out but how to hide that also so only particular specific file I can see no other file.
Below code which I have used:
Intent intent = new Intent(Intent.Action_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES,"application/pdf");
startActivityForResult(intent, FILE_REQUESTED);
What can I do to fix this?
I want to see only particular file only
Sorry, that is not an option with ACTION_OPEN_DOCUMENT.
I'm trying to use ACTION_GET_CONTENT with text/csv mime type but the result is that all files are displayed but grayed out in the file picker?
Here is my code:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/csv");
...
currentActivity.startActivityForResult(intent, READ_REQUEST_CODE, Bundle.EMPTY);
Tested on Android 7.1/8/9 with the same outcome. The following directory contains .json and .csv files.
Is this mime type even supported?
I don't think a csv is explicitly supported, instead you can just treat it as a normal plaintext file, and parse the content yourself like this:
intent.setType("text/*");
The downside is that the non-csv files will also be shown to the user, therefore, you might need to do some extra checking for the contents of the file.
If you really do need it to be a .csv being shown to the user, you can create your own file picking activity that filter everything else that does not have the .csv extension.
I have the same problem. Android seems to only recognize "text/comma-separated-values". Here's how I fixed it,
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
String[] mimetypes = {"text/csv", "text/comma-separated-values"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
I am new in android development and I just want to know how to do a customized file explorer that will only display pdf, text and image files.
I tried this example but I dont know how to filter the files that can be displayed :(
Android File Explore
Is there a way to display and select only the files mentioned above?
Take a look at #Smitted answer.
Create the intent:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
You can set the MIME types for the intent:
intent.SetType("application/pdf");
and add additional MIME types:
String[] mimetypes = {"image/*", "text/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
and start the activity:
StartActivityForResult(intent, FIND_FILE_REQUEST_CODE);
You can filter the files in the accept() of new FilenameFilter().
In my Android app, I use the following code to launch an image picker:
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/jpg");
startActivityForResult(intent, INTENT_PICK_IMAGE);
But unfortunately, the system gallery activity that is called by this also display videos. Is there a way to prevent this?
I use this to only allow image types:
intent.setType("image/*");
Edit: setType() is based on MIME type, not file extension (See here: http://developer.android.com/reference/android/content/Intent.html#setType(java.lang.String))
I am trying to use Android gallery to pick image. Launching gallery is easy for that purpose
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
However, I need to limit images that are shown in the gallery to specific path on device (i.e. to show images from single folder only). Is this possible to do and how?
Sorry, no this is not possible.
Also you are using this Intent protocol wrong. As per http://developer.android.com/reference/android/content/Intent.html#ACTION_PICK this protocol expects that you put the content: URI of the data set you want the picker to select from.
That said, you should consider ACTION_PICK deprecated. The modern action is ACTION_GET_CONTENT which is much better supported; you will find support of ACTION_PICK spotty and inconsistent. Unfortunately, ACTION_GET_CONTENT also does not let you specify a directory.
Why not ?
Intent galleryIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivity(galleryIntent)
Good luck with..