how to open bitmap in gallery in android

Raja picture Raja · May 3, 2013 · Viewed 7.1k times · Source

Hi I want to open image in gallery, below is my code

mImageView.setImageBitmap(AppUtil.getBitmapFromFile(obj.getImageUrl(), 200, 200));

    mImageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse(obj.getImageUrl()), "image/*");
            startActivity(intent);
        }
    });

but its showing NullPointerException

Uri.parse(obj.getImageUrl() returns below string

/mnt/sdcard/Pictures/app_images/pro20130429_170323_-1793725321.tmp

update: now i tried
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("file://sdcard/Pictures/app_images/pro20130429_170323_-1793725321.tmp"))); and getting an error that

05-03 16:40:18.460: E/AndroidRuntime(4764): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file://sdcard/Pictures/app_images/pro20130429_170323_-1793725321.tmp }

Answer

umesh picture umesh · May 3, 2013

try this one

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/Pictures/app_images/pro20130429_170323_-1793725321.tmp"), "image/*");
startActivity(intent);