简体   繁体   中英

Open multiple images in gallery intent

I need to open multiple images in gallery to view by sliding... I know how to open 1 image..

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

How can i view multiple images to view them all by sliding in a single intent.? I have the path of the images... And i need to view them in gallery.

The EXTRA_ALLOW_MULTIPLE option is set on the intent through the Intent.putExtra() method to select multiple images

Multiple Image selection available only for above API 18

intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

Full intent code is here:

Intent intent = new Intent(); intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"),1);

You can straight away show multiple images by accessing into your device's default gallery app.

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                photoPickerIntent.setType("image/*");
                startActivityForResult(photoPickerIntent, SELECT_PHOTO);

There are 2 ways to implement multi-selection of images in gallery:

1.Intent for getting multiple images

2.Define custom gallery with fetching and loading photos from native gallery.

Intent for getting multiple images:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);

For implementation of gallery see this link: http://www.technotalkative.com/android-select-multiple-photos-from-gallery/

it fetches multiple images and shows them in a gridview

不,你不能这样做....你需要创建一个新的视图活动

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM