imageview - Android: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT cat=[android.intent.category.OPENABLE] typ=image/* } -
i have 1 imageview
in layout file. want load image in imageview
when open app.
but happens when open app occurs error message
caused by: android.content.activitynotfoundexception: no activity found handle intent { act=android.intent.action.open_document cat=[android.intent.category.openable] typ=image/* }
here code
imageview mimageview; private static final int request_open_result_code=0; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_image_viewer_main); mimageview=(imageview)findviewbyid(r.id.imageview); intent intent= new intent(intent.action_open_document); intent.addcategory(intent.category_openable); intent.settype("image/*"); startactivityforresult(intent, request_open_result_code ); } @override protected void onactivityresult(int requestcode, int resultcode, intent resultdata) { if(requestcode==request_open_result_code && resultcode==result_ok){ uri uri=null; if(resultdata!=null){ uri=resultdata.getdata(); try { bitmap bitmap=getbitmapfromuri(uri); mimageview.setimagebitmap(bitmap); } catch (ioexception e) { e.printstacktrace(); } } } } private bitmap getbitmapfromuri(uri uri) throws ioexception{ parcelfiledescriptor parcelfiledescriptor=getcontentresolver().openfiledescriptor(uri, "r"); filedescriptor filedescriptor=parcelfiledescriptor.getfiledescriptor(); bitmap bitmap= bitmapfactory.decodefiledescriptor(filedescriptor); parcelfiledescriptor.close(); return bitmap; }
Comments
Post a Comment