1

I'm building an android app that can get images from the photos gallery.

two questions if I may:

1)

 Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        String action = intent.getAction();

        Uri uri = null;

        // if this is from the share menu
        if (Intent.ACTION_SEND.equals(action)) {
            if (extras.containsKey(Intent.EXTRA_STREAM))
            {
                try
                {
                    // Get resource path from intent callee
                     uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);

I have this uri:

content://media/external/images/media/27031

but my code fails here with no information (it just crashes), no log cat, not console error.

 try {
            if (uri !=null)
            {

            Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);

            imageView.setImageBitmap(bitmap);
            }

        } catch (IOException e) {
            e.printStackTrace();

            Log.e(this.getClass().getName(), e.toString());
        }

how can I solve this?

(it works for this url: Uri uri = Uri.parse("content://media/external/images/media/22719");

2) i plan to save all uri's in a data structure. That's the recommended way?

or is it better to keep the photos in a local app folder?

Update

I think the problem was that the failing image was on the external SD whereas the succeeding one was on a local SD.

How can i enable getting image from the external SD ?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

1 Answers1

0

some code for getting a bitmap from a 'share' action on a photo...

    Object obj = null;

        if (Intent.ACTION_SEND.equals(_action) && _type != null) {
            obj = _bundle.get("android.intent.extra.STREAM");
            if( getIntent().getType().startsWith("image/") && obj != null){
              if (obj instanceof android.net.Uri){ get((Uri)obj);}}

  get(Uri uri){
      Bitmap _bit = BitmapFactory.decodeStream(
       getContentResolver().openInputStream(uri),null,options);
}
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
  • Update I think the problem was that the failing image was on the external SD whereas the succeeding one was on a local SD. How can i enable getting image from the external SD ? – Elad Benda Sep 14 '13 at 13:16
  • not sure what you mean by local vs external SD but you could look over this link on extern mounted sdcard http://stackoverflow.com/questions/14449509/how-to-invoke-android-media-scanner-for-vendor-provided-external-sd-card-not-th – Robert Rowntree Sep 14 '13 at 14:16
  • local storage vs external storage (sd) I mean look at the path of these images: http://stackoverflow.com/questions/18802216/mediastore-images-media-getbitmap-gets-images-only-from-local-sd – Elad Benda Sep 14 '13 at 16:54