android - The Gallery Access -


i'm working on app lets display photo activity , share it. i'm trying code work image gallery. works google photos app, force closes when comes other apps. this?

package app.com.example.android.shoutoutapp;

import android.app.activity; import android.content.intent; import android.database.cursor; import android.net.uri; import android.os.bundle; import android.provider.mediastore; import android.view.view; import    android.view.view.onclicklistener; import android.widget.button; import android.widget.imageview;  public class mainactivity extends      activity {  private static final int select_picture = 1;  private string selectedimagepath; private imageview img;  public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      img = (imageview)findviewbyid(r.id.targetimage);      ((button) findviewbyid(r.id.add_photo))             .setonclicklistener(new onclicklistener() {                 public void onclick(view arg0) {                     intent intent = new intent();                     intent.settype("image/*");                     intent.setaction(intent.action_get_content);                     startactivityforresult(intent.createchooser(intent,"select picture"), select_picture);                 }             }); }  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);             img.setimageuri(selectedimageuri);         }     } }      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);     } } 

in manifest, images other apps need permission,

 <uses-permission android:name="android.permission.read_external_storage" /> 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -