Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access pictures from Pictures app in my android app

Just like the iPhone has a UIImagePickerController to let the user access pictures stored on the device, do we have a similar control in the Android SDK?

Thanks.

like image 271
lostInTransit Avatar asked Feb 15 '09 13:02

lostInTransit


People also ask

How do I access my Photos on Android?

On your Android phone or tablet, open Google Photos . At the bottom, tap Library Find the folder under Photos on device. If available, open your device folders to find your missing item. If you want your device folder items to appear in your Photos tab, you can back them up automatically.

How do I view my Photos on the photo app?

In the Photos app, tap the Photos tab, or tap the Albums tab, then tap a thumbnail. Swipe left or right to see the next or previous photo. Tap Edit, then use the controls at the bottom of the screen to make changes.

Where are Photos on Android stored?

Your photos will be in one of two areas: The Pictures folder or the DCIM folder. Photos you took with your phone will likely be in your DCIM folder, while other photos or images (like screenshots) you keep on your phone will likely be in the Pictures folder.


1 Answers

You can usestartActivityForResult, passing in an Intent that describes an action you want completed and and data source to perform the action on.

Luckily for you, Android includes an Action for picking things: Intent.ACTION__PICK and a data source containing pictures: android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI for images on the local device or android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI for images on the SD card.

Call startActivityForResult passing in the pick action and the images you want the user to select from like this:

startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE); 

Then override onActivityResult to listen for the user having made a selection.

@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {   super.onActivityResult(requestCode, resultCode, data);   if (requestCode == SELECT_IMAGE)     if (resultCode == Activity.RESULT_OK) {       Uri selectedImage = data.getData();       // TODO Do something with the select image URI     }  } 

Once you have the image Uri you can use it to access the image and do whatever you need to do with it.

like image 116
Reto Meier Avatar answered Sep 21 '22 21:09

Reto Meier