java - Capturing Image in Android getting error on onActivityResult -
i trying capture image in android getting error like:
fatal exception: main process: com.pace.planes, pid: 18741 java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1888, result=-1, data=intent { dat=content://media/external/images/media/4532 }} activity {com.pace.planes/com.pace.planes.confirmation}: java.lang.nullpointerexception
while used suggested solutions on stack overflow. here code:
captureimage.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent cameraintent = new intent(android.provider.mediastore.action_image_capture); startactivityforresult(cameraintent, camera_request); } });
and here onactivityresult code:
protected void onactivityresult(int requestcode, int resultcode, intent data) { if(resultcode != result_canceled && data != null){ if (requestcode == camera_request && resultcode== activity.result_ok) { bitmap imagebitmap = (bitmap) data.getextras().get("data"); uri tempuri = getimageuri(getapplicationcontext(), imagebitmap); // call method actual path finalfilepath = new file(getrealpathfromuri(tempuri)); // imagebitmap = compressor.getdefault(this).compresstobitmap(finalfilepath); captureimage.setscaletype(imageview.scaletype.fit_xy); imagebitmap = new compressor.builder(this) .setquality(10) .setcompressformat(bitmap.compressformat.png) .setdestinationdirectorypath(environment.getexternalstoragepublicdirectory(environment.directory_pictures).getabsolutepath()) .build() .compresstobitmap(finalfilepath); captureimage.setimagebitmap(imagebitmap); //set status image seleted isimageselected = true; } } } public uri getimageuri(context incontext, bitmap inimage) { bytearrayoutputstream bytes = new bytearrayoutputstream(); inimage.compress(bitmap.compressformat.jpeg, 100, bytes); string path = mediastore.images.media.insertimage(incontext.getcontentresolver(), inimage, "title", null); return uri.parse(path); } public string getrealpathfromuri(uri uri) { cursor cursor = getcontentresolver().query(uri, null, null, null, null); cursor.movetofirst(); int idx = cursor.getcolumnindex(mediastore.images.imagecolumns.data); return cursor.getstring(idx); }
Comments
Post a Comment