You can use startActivityForResult by passing in an Intent that describes the action you want to complete and the data source to perform the action.
Luckily for Android, there is an action in Android for choosing things: Intent.ACTION__PICK and a data source containing photos: 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.
A call to startActivityForResult passing in the select action and the image you want to select, for example:
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE);
Then override onActivityResult to listen to the user by making a choice.
@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();
Once you have a Uri image, you can use it to access the image and do whatever you need with it.
Reto Meier Feb 15 '09 at 16:26 2009-02-15 16:26
source share