Skip to content Skip to sidebar Skip to footer

Android Open Gallery From Folder

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); int

Solution 1:

Try This

Intent i=newIntent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(newFile(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.

publicvoidShowPhoto(File imageFile) {

    StringmediaId="";

    String[] projection = newString[] {
            MediaStore.Images.Media._ID,
            MediaStore.Images.Media.DISPLAY_NAME
    };

    Cursorcursor= getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, null, null, null);

    while (cursor != null && cursor.moveToNext()) {
        Stringname= cursor.getString((cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME)));
        if(name.equals(imageFile.getName())){
            mediaId = cursor.getString((cursor.getColumnIndex(MediaStore.Images.ImageColumns._ID)));
            break;
        }
    }

    UrimediaUri= MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

    if(!mediaId.equals("")){
        mediaUri = mediaUri.buildUpon()
                .authority("media")
                .appendPath(mediaId)
                .build();
    }

    Log.d("TagInfo","Uri:  "+mediaUri);

    Intentintent=newIntent(Intent.ACTION_VIEW, mediaUri);
    startActivity(intent);

}

Solution 3:

Try this way,hope this will help you to solve your problem.

finalintOPEN_GALLERY=1Intentintent=newIntent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, ""), OPEN_GALLERY);

Post a Comment for "Android Open Gallery From Folder"