android - Uploading an image from phone storage -
i trying make user upload image file his/her phone gallery app. have managed invoke gallery user selects image. following error:
java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1, result=-1, data=intent { dat=content://media/external/images/media/7963 (has extras) }} activity {com.progrmor.tombstone.android/com.progrmor.tombstone.android.androidlauncher}: java.lang.securityexception: permission denial: reading com.android.providers.media.mediaprovider uri content://media/external/images/media/7963 pid=16802, uid=10409 requires android.permission.read_external_storage, or granturipermission() @ android.app.activitythread.deliverresults(activitythread.java:4060) @ android.app.activitythread.handlesendresult(activitythread.java:4103) @ android.app.activitythread.access$1400(activitythread.java:177) @ android.app.activitythread$h.handlemessage(activitythread.java:1497) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:145) @ android.app.activitythread.main(activitythread.java:5944) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1389) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1184) caused by: java.lang.securityexception: permission denial: reading com.android.providers.media.mediaprovider uri content://media/external/images/media/7963 pid=16802, uid=10409 requires android.permission.read_external_storage, or granturipermission()
below codes invoking gallery:
public void onactivityresult(int request, int response, intent data) { super.onactivityresult(request, response, data); if(response == result_ok) { if(request == select_picture) { uri selectedimage = data.getdata(); selectedimagepath = getpath(selectedimage); } } } public string getpath(uri uri) { // safety built in if( uri == null ) { // todo perform logging or show user feedback return null; } // try retrieve image media store first // work images selected gallery string[] projection = { mediastore.images.media.data }; cursor cursor = managedquery(uri, projection, null, null, null); if( cursor != null ){ int column_index = cursor .getcolumnindexorthrow(mediastore.images.media.data); cursor.movetofirst(); return cursor.getstring(column_index); } // our fallback here return uri.getpath(); } @override public void imageupload() { runonuithread(new runnable() { @override public void run() { intent intent = new intent(); intent.settype("image/"); intent.setaction(intent.action_get_content); startactivityforresult(intent.createchooser(intent, "select picture"), select_picture); } }); }
then call method in 1 of screen classes:
boximage1.addlistener(new changelistener() { @override public void changed(changeevent event, actor actor) { imageupload(); } }); }
so i'm asking is: how can make click on picture upload actual picture texture or something? want chosen image drawn on screen when pick it.
need add proper permission in manifest
<uses-permission android:name="android.permission.read_external_storage" />
Comments
Post a Comment