Retrieve bitmap from uri

Robert picture Robert · Dec 26, 2013 · Viewed 84.1k times · Source

I have included 'share via myApp' option. I inserted following code in the receiving activity class.

    // Get the intent that started this activity
    Intent intent = getIntent();
    Uri data = intent.getData();

    // Figure out what to do based on the intent type
    if (intent.getType().indexOf("image/") != -1) {
        // Handle intents with image data ...
}

What is the next step to retrieve bitmap image.

Answer

Chintan Khetiya picture Chintan Khetiya · Dec 26, 2013

As you have already get the Uri. Now you have to pass that Uri in getBitmap() to get bitmap and use that bitmap.

Uri imageUri = intent.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),imageUri);
Imageview my_img_view = (Imageview ) findViewById (R.id.my_img_view);
my_img_view.setImageBitmap(bitmap);