当我按下按钮打开相机时,我的应用程序崩溃了。
05-18 19:33:41.644 386-2041/? E/CameraService: Permission Denial: can't use the camera pid=18519, uid=10159
05-18 19:33:41.648 18519-18519/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: involved.pose9, PID: 18519
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.<init>(Camera.java:511)
at android.hardware.Camera.open(Camera.java:368)
at involved.pose9.CameraActivity$1.onClick(CameraActivity.java:48)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
答案 0 :(得分:2)
将此添加到您的清单:
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
答案 1 :(得分:0)
使用此
要拨打相机,您可以使用:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivity(intent);
图像将自动保存在默认目录中。
您需要在 AndroidManifest.xml中设置相机的权限:
<uses-permission android:name="android.permission.CAMERA"> </uses-permission>
现在使用上述方法没有摄像头的设备或只有前置摄像头的设备将无法找到/安装该应用程序。
将此添加到您的清单:
<uses-feature
android:name="android.hardware.camera"
android:required="false" />