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.
Related
I am trying to open a directory for user to choose an excel document from it.
However, my file picker opens in the "recent" location.
Is there a way to start it from a specific directory using new versions of Android?
This is my code:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.DIRECTORY_DOCUMENTS);
intent.setDataAndType(uri, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
startActivity(Intent.createChooser(intent, "Open folder"));
You need to set EXTRA_INITIAL_URI:
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)
Unfortunately, the Intent.ACTION_GET_CONTENT does not support opening in a specific location. The only way to choose a specific location is by using a third-party file picker library, such as FilePicker, aFileChooser, etc.
You can use these libraries to create a custom file picker that opens in a specific location and allows the user to choose a file. Then, you can call the custom file picker in your code instead of using Intent.ACTION_GET_CONTENT.
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.
How to open default file manager app that let you choose a file but only with extension .epub or .pdf programatically via Intent?
The code shown is the declaration of the intent that you have to start for opening the default file manager app that let you choose a file but only with extension .epub or .pdf, I hope it will be useful.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/epub+zip");
String[] mimetypes = {"application/epub+zip", "application/pdf"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent,PICKFILE_RESULT_CODE);
It is a mix of solutions I found that work so maybe it is redundant. Let me know what you think!
I want to programatically launch a default file explorer to show me the contents of a folder.
I'm using this code, but it crashes:
Uri startDir = Uri.fromFile(new File("/sdcard/DCIM/Camera"));
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(startDir);
startActivity(intent);
LogCat shows "No Activity found to handle the Intent"...
What's my best option to do this? I want the user to see the contents of the folder and be able to click the files (e.g. click a video and launch it with default player, click a PDF and open it etc).
Unfortunately there seem to be no standard way to do this, I was searching for the exact same thing before and couldn't find out any solution. There are 2 alternative methods that might work for you:
1) Use a general intent and let the user pick his/her file manager
This is safe and easy but a little far from what we really want
Uri startDir = Uri.fromFile(new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/DCIM/Camera"));
Intent intent = new Intent();
intent.setData(startDir);
intent.setType("*/*");
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
Don't use intent.setType("file/*");, it's not a standard MIME type.
2) Use Specific Intents that the famous file managers provide The well known file managers have their own custom intent filters that accept a directory path which allows simple browsing. Some of them are here: OI file manager, ES Explorer
Maybe you could check if the user have these specific file managers installed and then use this solution, else fallback to general intent.
For now these are the only two options you have. I will update this post if I find out any better solution.
Although I could not get the OI file manager to go to a specific directory, the following opens up the OI File Manager directly and goes to the last directory it was in.
Intent importFileIntent = new Intent();
importFileIntent.setType( "file/*" );
// Does nothing.
// Uri startingDir = Uri.fromFile( new File(
// Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera"));
// importFileIntent.setData( startingDirectory );
importFileIntent.setAction( Intent.ACTION_GET_CONTENT );
// Ensure that there's an activity to handle the intent.
if (importFileIntent.resolveActivity(getPackageManager()) == null) return;
startActivityForResult(importFileIntent, REQUEST_FILE_IMPORT);
If anybody has further success, I would love to hear it.
I am trying to open a jpg image file in gallery. This gives a error. I am using the code below
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("/mnt/sdcard/image123.jpg"),"image/jpeg");
startActivityForResult(intent, 900);
This gives a option to open file in gallery. I select Gallery from the list. But it does not open up. I use ASTRO file manager and open the same image file. It opens up fine now. Please let me know if something is wrong.
Where do you got /mnt/sdcard. Try Environment.getExternalStorageDirectory().getAbsolutePath() instead.
Specified Image Path? You can't. Please Refer My Question as How to access different File Manager specific path. Refer this link and then you got a answer.