相机意图返回NULL(Camera Intent Returns Null)

2019-07-30 15:29发布

我试图捕捉图像和视频从我的使用意图默认摄像头的Android应用程序。

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

            startActivityForResult(intent, IMAGE_FROM_CAMERA);

使用上述代码我试图捕捉的图像和在onActivityResult我在在数据获取空data.getData()

我试图通过开放的我们的意图,但是开放的我们变空。

相机的意图是不能写在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

Answer 1:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
 File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
 File output = new File(dir, "camerascript.png");
 cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(output));
startActivityForResult(cameraIntent, 1);


文章来源: Camera Intent Returns Null