android - Can't receive Intent.extras() from Camera after making a photo -
i found it's common problem capturing photo , receiving full size photo instead of thumbnail (according to: http://developer.android.com/training/camera/photobasics.html ). taking photo , receiving thumbnail easy, rest of tutorial seems uncomplete , not working. resolved in easy way?
public class takephoto extends activity{ static final int request_image_capture = 1; static final int request_take_photo = 1; private string mcurrentphotopath; private imageview mimageview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.take_photo); mimageview = (imageview) findviewbyid(r.id.imageview); dispatchtakepictureintent(); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == request_take_photo && resultcode == result_ok) { bundle extras = data.getextras(); bitmap imagebitmap = (bitmap) extras.get("data"); mimageview.setimagebitmap(imagebitmap); } } private void dispatchtakepictureintent() { intent takepictureintent = new intent(mediastore.action_image_capture); // ensure there's camera activity handle intent if (takepictureintent.resolveactivity(getpackagemanager()) != null) { // create file photo should go file photofile = null; try { photofile = createimagefile(); } catch (ioexception ex) { // error occurred while creating file log.i("asd", ex.tostring()); } // continue if file created if (photofile != null) { takepictureintent.putextra(mediastore.extra_output, uri.fromfile(photofile)); startactivityforresult(takepictureintent, request_take_photo); } } } private file createimagefile() throws ioexception { // create image file name string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date()); string imagefilename = "jpeg_" + timestamp + "_"; file storagedir = environment.getexternalstoragepublicdirectory( environment.directory_pictures); file image = file.createtempfile( imagefilename, /* prefix */ ".jpg", /* suffix */ storagedir /* directory */ ); // save file: path use action_view intents mcurrentphotopath = "file:" + image.getabsolutepath(); return image; }
}
04-25 18:01:14.239 17281-17281/com.(package).bazaar e/androidruntime﹕ fatal exception: main process: com.(package).bazaar, pid: 17281 java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1, result=-1, data=null} activity {com.(package).bazaar/com.(package).bazaar.takephoto}: java.lang.nullpointerexception: attempt invoke virtual method 'android.os.bundle android.content.intent.getextras()' on null object reference @ android.app.activitythread.deliverresults(activitythread.java:3626) @ android.app.activitythread.handlesendresult(activitythread.java:3669) @ android.app.activitythread.access$1300(activitythread.java:148) @ android.app.activitythread$h.handlemessage(activitythread.java:1341) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5312) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:901) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:696) caused by: java.lang.nullpointerexception: attempt invoke virtual method 'android.os.bundle android.content.intent.getextras()' on null object reference @ com.klangstudios.bazaar.takephoto.onactivityresult(takephoto.java:46) @ android.app.activity.dispatchactivityresult(activity.java:6161) @ android.app.activitythread.deliverresults(activitythread.java:3622) at android.app.activitythread.handlesendresult(activitythread.java:3669) at android.app.activitythread.access$1300(activitythread.java:148) at android.app.activitythread$h.handlemessage(activitythread.java:1341) at android.os.handler.dispatchmessage(handler.java:102) at android.os.looper.loop(looper.java:135) at android.app.activitythread.main(activitythread.java:5312) at java.lang.reflect.method.invoke(native method) at java.lang.reflect.method.invoke(method.java:372) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:901) at com.android.internal.os.zygoteinit.main(zygoteinit.java:696)
i not expect data
null
there. however, there should not extras on intent
. "data"
if not specifying extra_output
. if specifying extra_output
, go photo path provided in extra_output
, , ignore intent
delivered onactivityresult()
.
with regards null
data
intent
itself, may peculiar camera app using. please bear in mind using action_image_capture
means relying upon third-party app take picture, , third-party apps can have bugs.
Comments
Post a Comment