Android open gallery from folder
Solution 1
Try This
Intent i=new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(new File(path)), "image/*");
startActivity(i);
See these Links
How can I use Intent.ACTION_VIEW to view the contents of a folder?
Android ACTION_VIEW Multiple Images
Java and Android: How to open several files with an Intent?
if this solves your problem. Also check
https://www.google.co.in/?gfe_rd=cr&ei=c5n9U6ruE7DO8gfXz4G4BA&gws_rd=ssl#q=view+like+gallery
also check Gallery
widget
Solution 2
This question is from five years ago, However I want to give an answer that worked for me instead of the correct answer.
In order to show the photo and slide through the others photos, we need to give to the intent not the file uri but the media uri.
public void ShowPhoto(File imageFile) {
String mediaId = "";
String[] projection = new String[] {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DISPLAY_NAME
};
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, null, null, null);
while (cursor != null && cursor.moveToNext()) {
String name = cursor.getString((cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME)));
if(name.equals(imageFile.getName())){
mediaId = cursor.getString((cursor.getColumnIndex(MediaStore.Images.ImageColumns._ID)));
break;
}
}
Uri mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
if(!mediaId.equals("")){
mediaUri = mediaUri.buildUpon()
.authority("media")
.appendPath(mediaId)
.build();
}
Log.d("TagInfo","Uri: "+mediaUri);
Intent intent = new Intent(Intent.ACTION_VIEW, mediaUri);
startActivity(intent);
}
Related videos on Youtube
Nero
Updated on October 01, 2022Comments
-
Nero over 1 year
I want to show a photo in android gallery, and be able to slide throw the others photos on that folder.
Intent intent = new Intent(Intent.ACTION_VIEW); File f = new File(path); intent.setDataAndType(Uri.parse("file://" + f.getAbsolutePath()), "image/*"); mContext.startActivity(intent);
thats how i am doing it now, but wont let me slide throw the rest of the images in the folder. i tried:
How to open one particular folder from gallery in android?
Built-in gallery in specific folder
Without any luck. i would be really happy if someone have the solution. Thanks!
-
Nero over 9 yearssame result, it shows me the image but wont let me slide between the other images of the folder :C
-
Nero over 9 yearsnope this wont do, i am already showing thumbnails of the photos in the folder i need to open them in fullscreen and slide throw them. Thanks anyway!
-
Nitin over 9 yearsjust check if you are using the correct path.just print the Path using Log.e("My Path",path);. The code above is working. Hope this helps you :)
-
Nero over 9 yearsthe path is ok, it shows me the image, dont let me slide sadly XD
-
Nero over 9 yearsI think its just not posible to do what i want to do, like some ppl say it depends on what the image viewer do with the uri i guess i will make my own image viewer so i can do whatever i want with it i will make yours as answer b/c you link to the its not posible post so thank you! :D