Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Let user pick image or video from Gallery

Is it possible to to start Gallery in such a way so both pictures and videos are shown?

Thanks

like image 215
Asahi Avatar asked Feb 07 '11 13:02

Asahi


2 Answers

Pick Audio file from Gallery:

//Use MediaStore.Audio.Media.EXTERNAL_CONTENT_URI Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI); 

Pick Video file from Gallery:

//Use MediaStore.Audio.Media.EXTERNAL_CONTENT_URI Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI); 

Pick Image from gallery:

//Use  MediaStore.Images.Media.EXTERNAL_CONTENT_URI Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 

Pick Media Files or images:

 Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/* video/*"); 
like image 161
Jorgesys Avatar answered Sep 27 '22 17:09

Jorgesys


You start the gallery as such:

Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); pickIntent.setType("image/* video/*"); startActivityForResult(pickIntent, IMAGE_PICKER_SELECT); 

then in your onActivityResult you can check if video or image was selected by doing this:

public void onActivityResult(int requestCode, int resultCode, Intent data) {  if (resultCode == RESULT_OK) {     Uri selectedMediaUri = data.getData();     if (selectedMediaUri.toString().contains("image")) {         //handle image     } else  if (selectedMediaUri.toString().contains("video")) {         //handle video     } } 
like image 44
Siavash Avatar answered Sep 27 '22 17:09

Siavash