I want to show downloaded file in File Manager by giving the File absolute Path.I read a lot about it and find same thing
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(file.getAbsolutePath());
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
And it results to view only recent files that has been viwed. Please guide to Open File Manager while navigating it to file whose absolute path has been given.
I read a lot about it and find same thing
ACTION_GET_CONTENT has little to do with a file manager.
Please guide to Open File Manager while navigating it to file whose absolute path has been given.
There is nothing on Android for this, sorry.
Related
I have an app that downloads files to folder selected by the user.
I get access to the folder using :
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent,REQUEST_PICK_FOLDER_TO_DOWNLOAD);
create the downloaded file with
DocumentFile newFile = destDir.createFile(mime, file.getFileName());
I need to share the file. For example if this is a text file, pdf or word doc user can open it in the appropriate app.
File URI seems pretty strange:
"content://com.android.externalstorage.documents/tree/primary%3Amy_logs/document/primary%3Amy_logs%2Fford-f-150-raptor-2019-491746%20(1).jpg"
But it is a file created with createFile and I am able to write the contents.
I am not sure FileProvider can help as the dest folder is any folder on the device.
I am not sure is there anyway to share that URI with any other app?
Thank you very much!
V
I'm trying to use Intent ACTION_GET_CONTENT to open an application such as (File Manager, File explorer etc...). However once I am in the File Manager, I am only able to open the file. The Copy to.. and Move to... capabilities are not shown when opening File Manager app using this method. Is ACTION_GET_CONTENT only used for opening files?
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath());
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
Here is the image showing the open option only:
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.