I want to open the default gallery app to a folder (named fooo) in the primary storage. I thought the easiest way would be to use Intents. When I use this code for my intent, the gallery app opens but it shows no image. I check with file explorer and there are images.
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/fooo/");
intent.setDataAndType(uri, "image/*");
startActivity(intent);
First, there is no requirement for any ACTION_VIEW activity to be able to handle a directory as the Uri.
Second, your MIME type is incorrect, as a directory is not an image.
Third, your Uri is invalid, because it lacks a scheme. Replace:
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/fooo/");
with:
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "fooo");
Related
I have a file stored in my App's storage like this:
/storage/emulated/0/Android/data/com.example.myapp/files/App files/90210_John_s_Resume.pdf
the 90210 at the beginning is a file ID for internal purposes only, and I give the user the option to save this file to Downloads folder, where I remove the 90210 prefix. But I also provide the user to preview the file using ACTION_VIEW intent. This causes an issue where the file name in the previewed app still has the 90210 prefix. Is there a way to overcome this?
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri fileUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", finalFile);//NO I18N
intent.setDataAndType(fileUri, URLConnection.guessContentTypeFromName(fileUri.toString()));
context.startActivity(intent);
I'm trying to open a specific folder using intent, but the device's recent folder open instead.
Code:
Uri uri = Uri.parse(filepath);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT,uri);
intent.setDataAndType(uri,"text/plain");
StartActivityForResult(intent, REQUEST_CODE);
ACTION_GET_CONTENT does not take a Uri, so yours is ignored.
With ACTION_OPEN_DOCUMENT, you can use EXTRA_INITIAL_URI to provide some document tree (e.g., from ACTION_OPEN_DOCUMENT_TREE) that should be used as the initial location.
I am trying to open "MyFolder" but it is opening recent files folder.
I have tried many techniques, nothing seems to work.
All are similar to this code:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() +
File.separator + "MyFolder" + File.separator);
intent.setDataAndType(uri, "*/*");
startActivity(intent);
Is it possible, if yes, how can I do it?
Any help would be appreciated.
First, there is no standard Intent action to "open" a filesystem directory on Android.
Second, the value that you pass to Uri.parse() needs to be a string form of a Uri, with a scheme. If you are going to create a Uri from a File, use Uri.fromFile(), rather than turning the File into a String and passing that String to Uri.parse().
Third, ACTION_GET_CONTENT does not take a Uri.
I could just get my files on removable storage by action_open_document tree and it gives me a document file. I can not open this file with Action_view.
The URI from document file did work!
I can open image file with action view .
String uri=DocumentFile.getUri.toString;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri);
intent.setDataAndType(Uri.parse(uri), "video/mp4");
activity.startActivity(intent);
Other apps do not have access to that content. Add FLAG_GRANT_READ_URI_PERMISSION to the Intent to pass along your own read access to the third-party app.
I have designed two buttons.One button for selecting the file and another button for to open the selected file.I have selected the file correctly and the file path also retrieved.But i cant open the particular file directly by the file path.Any one I have tried something like this
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ selectedFilePath);
intent.setDataAndType(uri, "text/csv");
startActivity(Intent.createChooser(intent, "Open folder"));
First, ACTION_GET_CONTENT does not accept a Uri as input.
Second, ACTION_GET_CONTENT has nothing to do with opening a file. Presumably, you should be using ACTION_VIEW.
Third, the value that you are passing to Uri.parse() is not a String form of a Uri.
Also, I would expect few Android devices to have an ACTION_VIEW activity for text/csv content.