无法让网络摄像头在android模拟器中工作,无法在android手机上正常工作

时间:2018-10-22 19:16:12

标签: android android-studio android-emulator

我正在和其他几个人一起进行我的顶点项目。我们有一个应用程序,该应用程序应该拍照并使用Google MLkit对图像进行图像处理。它在我朋友的android手机上可以正常工作,但是由于我没有,所以我需要设置网络摄像头来测试和完成项目的一部分。我花了几个小时试图弄清楚这一点,但是没有运气。

这是错误:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pg.teethdetection, PID: 3171
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pg.teethdetection/com.pg.teethdetection.DetectTeethActivity}: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera2/com.android.camera.CaptureActivity clip={text/uri-list U:content://com.pg.teethdetection.fileprovider/my_images/JPEG_20181022_150939_8076588917693759740.jpg} (has extras) } from ProcessRecord{56c9a53 3171:com.pg.teethdetection/u0a85} (pid=3171, uid=10085) with revoked permission android.permission.CAMERA
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera2/com.android.camera.CaptureActivity clip={text/uri-list U:content://com.pg.teethdetection.fileprovider/my_images/JPEG_20181022_150939_8076588917693759740.jpg} (has extras) } from ProcessRecord{56c9a53 3171:com.pg.teethdetection/u0a85} (pid=3171, uid=10085) with revoked permission android.permission.CAMERA
    at android.os.Parcel.createException(Parcel.java:1942)
    at android.os.Parcel.readException(Parcel.java:1910)
    at android.os.Parcel.readException(Parcel.java:1860)
    at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:3755)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1669)
    at android.app.Activity.startActivityForResult(Activity.java:4586)
    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
    at android.app.Activity.startActivityForResult(Activity.java:4544)
    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:754)
    at com.pg.teethdetection.DetectTeethActivity.dispatchTakePictureIntent(DetectTeethActivity.java:160)
    at com.pg.teethdetection.DetectTeethActivity.onCreate(DetectTeethActivity.java:134)
    at android.app.Activity.performCreate(Activity.java:7136)
    at android.app.Activity.performCreate(Activity.java:7127)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:193) 
    at android.app.ActivityThread.main(ActivityThread.java:6669) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
 Caused by: android.os.RemoteException: Remote stack trace:
    at com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1788)
    at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:717)
    at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:544)
    at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:1099)
    at com.android.server.am.ActivityStarter.execute(ActivityStarter.java:486)

我尝试为模拟器使用不同的系统映像,将webcam0设置为正反两个。

请求权限代码:

 @Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_CAMERA: {
            for (int i = 0, len = permissions.length; i < len; i++) {
                String permission = permissions[i];

                if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                    boolean
                            showRationale =
                            ActivityCompat.shouldShowRequestPermissionRationale(
                                    this, permission);

                    if (showRationale) {
                        showAlert();
                    } else if (!showRationale) {
                        // user denied flagging NEVER ASK AGAIN
                        // you can either enable some fall back,
                        // disable features of your app
                        // or open another dialog explaining
                        // again the permission and directing to
                        // the app setting
                        saveToPreferences(DetectTeethActivity.this, ALLOW_KEY, true);
                    }
                }
            }
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
} 

0 个答案:

没有答案