Opening Image File gives error in Android - android

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.

Related

Android open file manager how to show only particular file only

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.

Opening image with Intent through absolute file path

I am new to android development.
I am trying to open the default gallery app to view an image like this:
Uri u = Uri.parse((String) gridView.getAdapter().getItem(position);
Intent i = new Intent();
i.setDataAndType(u, "image/*");
i.setAction(Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(i);
I provide the file paths to my images like this:
/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20191023-WA0045.jpg
/storage/emulated/0/Pictures/9GAG/1565987862000.jpg
My App and Google Photos can display the image given this path, the Samsung Gallery( tested on Android Oreo) or the Xiaomi Gallery App (tested on Android X) can't find the image; also if i try to add "content://" or "file://" at the beginning.
I suspect that the apps want to have a Content URI or some kind of symbolic link without the "/storage/emulated/0/" part instead of a File URI. I searched for methods to get the content URI out of the file path, but didn't find any examples for Android X.
So what is the correct URI to pass on through the Intent and how do i get it?
Or maybe somebody knows a better way to just open the gallery app to a specific picture i provide by an absolute file path (Both External Storage and SD Card)?
Thank you in advance and greetings!
copied from this question here , this might work for you
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16"))); /** replace with your own uri */

How to open File manager navigated to specific directory in android?

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.

Android Java: Get Bitmap in Gallery

I have a Bitmap saved in the directory: Environment.getExternalStorageDirectory()+ File.separator + "Images" in a subdirectory. With a fileManager i can find the image and open it. But in the Gallery of the Smartphone i can't find the Image.
How can i get it there?
To be make you file known by the Gallery you need to call the MediaScanner:
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);
See also: https://www.grokkingandroid.com/adding-files-to-androids-media-library-using-the-mediascanner/
You can actually directly access the Pictures directory. To do this, use
getExternalStoragePublicDirectory(String type)
, where type is equal to Environment.DIRECTORY_PICTURES.
See http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory%28java.lang.String%29 for more info.
That's cleaner than supposing that pictures are always stored in a directory called "Images"...
Now to force the Gallery to register the change, look at https://stackoverflow.com/a/15837638/2984973 .
To quote the answer, you want to broadcast an intent specifying your new picture, likewise:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(myNewFile)));

unable to open particular folder inside gallery

how i can open a specific folder in gallery.
ex :name of folder is my folder.
when user click Button it directly open my folder inside default gallery.
how can i do this?
Intent intent=new Intent(Intent.ACTION_VIEW);
Uri uri=Uri.fromFile(new File(Environment.getExternalStorageDirectory().toString()+"/video"));
intent.setType("video/mp4");
startActivityForResult(Intent.createChooser(openGallary, "Select Video"), 0);
This answer was given twice already. Please use Google first next time. The link that abbas.aniefa gave was my second hit on Google when searching "ACTION_VIEW specific gallery".
The answer is also given here.

Categories

Resources