我正在尝试使用 Intent 使用默认相机从我的 android 应用程序中捕获图像和视频。
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, IMAGE_FROM_CAMERA);
使用上面的代码,我尝试捕获图像,并在onActivityResult
数据中获取 Nulldata.getData()
我尝试有意传递 Uri,但 Uri 变空了。
相机意图无法在 uri 上写入图像。我需要 uri 用电子邮件发送图像视频。
错误日志
07-26 21:16:54.125: E/AndroidRuntime(6142): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.cam/com.cam.CameraDemoActivity}: java.lang.NullPointerException
07-26 21:16:54.125: E/AndroidRuntime(6142): at android.app.ActivityThread.deliverResults(ActivityThread.java:3712)
07-26 21:16:54.125: E/AndroidRuntime(6142): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3754)
07-26 21:16:54.125: E/AndroidRuntime(6142): at android.app.ActivityThread.access$2800(ActivityThread.java:135)
07-26 21:16:54.125: E/AndroidRuntime(6142): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2162)
07-26 21:16:54.125: E/AndroidRuntime(6142): at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 21:16:54.125: E/AndroidRuntime(6142): at android.os.Looper.loop(Looper.java:143)
07-26 21:16:54.125: E/AndroidRuntime(6142): at android.app.ActivityThread.main(ActivityThread.java:4914)
07-26 21:16:54.125: E/AndroidRuntime(6142): at java.lang.reflect.Method.invokeNative(Native Method)
07-26 21:16:54.125: E/AndroidRuntime(6142): at java.lang.reflect.Method.invoke(Method.java:521)
07-26 21:16:54.125: E/AndroidRuntime(6142): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-26 21:16:54.125: E/AndroidRuntime(6142): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-26 21:16:54.125: E/AndroidRuntime(6142): at dalvik.system.NativeStart.main(Native Method)
07-26 21:16:54.125: E/AndroidRuntime(6142): Caused by: java.lang.NullPointerException
07-26 21:16:54.125: E/AndroidRuntime(6142): at com.cam.CameraDemoActivity.onActivityResult(CameraDemoActivity.java:48)
07-26 21:16:54.125: E/AndroidRuntime(6142): at android.app.Activity.dispatchActivityResult(Activity.java:3931)
07-26 21:16:54.125: E/AndroidRuntime(6142): at android.app.ActivityThread.deliverResults(ActivityThread.java:3708)
07-26 21:16:54.125: E/AndroidRuntime(6142): ... 11 more