android - Accessing and using images from the Gallery -


i have spent days researching issue , getting @ all. things have been accepted correct others not working me @ all, , keywords using not exist.

all trying ask user select image gallery. want store selection bitmap, convert size of image, , save file.

they have option same thing using camera, , code works perfectly. not sure why gallery difficult. here code (starting line below won't add code block reason):

if (requestcode == gallery_request && resultcode == result_ok && null != data) {              final context context=this;             intent j=new intent(context,playerselection.class);             intent intent = new intent();             intent.settype("image/*");             intent.setaction(intent.action_get_content);             uri selectedimageuri = data.getdata();             string selectedimage = selectedimageuri.getpath();             toast.maketext(getapplicationcontext(), selectedimage, toast.length_long).show();             string fname = new file(getfilesdir(), selectedimage).getabsolutepath();             fname = fname + ".jpg";             toast.maketext(getapplicationcontext(), fname, toast.length_long).show();             try {                bitmap gallerytemp = mediastore.images.media.getbitmap(this.getcontentresolver(),selectedimageuri);             } catch (ioexception e) {                e.printstacktrace();             }             //bitmap gallerypic = bitmap.createscaledbitmap(gallerytemp, 50, 50, false);             //saveimagefile(gallerytemp);             //startactivity(j);         } 

the sections have commented out above app fails. when path file, directed data\data\app.name\files\external\images\media\18630, actual file exists in **phone\dcim\camera**

i think issue lies, when try manipulate, or @ image (bitmap gallerytemp), app crashes.

this method use call above process:

case r.id.btngallery:

            intent = new intent(intent.action_pick, mediastore.images.media.internal_content_uri);             startactivityforresult(i, gallery_request);             break; 

any ideas? have read practically exists on subject , nothing working me.

this may you:

public void onactivityresult(int requestcode, int resultcode, intent data) {     if (resultcode == result_ok) {         if (requestcode == select_picture) {             uri selectedimageuri = data.getdata();             selectedimagepath = getpath(selectedimageuri);             system.out.println("image path : " + selectedimagepath);         }     } }  public string getpath(uri uri) {     string[] projection = { mediastore.images.media.data };     cursor cursor = managedquery(uri, projection, null, null, null);     int column_index = cursor.getcolumnindexorthrow(mediastore.images.media.data);     cursor.movetofirst();     return cursor.getstring(column_index); } 

you have path 'media store' content provider gives path actual image, thumbnail etc.