禁用相机但不起作用

时间:2013-01-16 11:51:49

标签: android

我写了这些代码;

    case R.id.button_camera:
        if ( gate == false ) {
            Toast.makeText(this, "enable camera", Toast.LENGTH_LONG).show();
            devicePolicyManager. setCameraDisabled(demoDeviceAdmin, false);
        } 
        else {
            Toast.makeText(this, "disable camera", Toast.LENGTH_LONG).show();
            devicePolicyManager. setCameraDisabled(demoDeviceAdmin, true);
        }
        break;

我犯了以下错误;

01-16 11:50:12.833: E/AndroidRuntime(799): FATAL EXCEPTION: main
01-16 11:50:12.833: E/AndroidRuntime(799): java.lang.IllegalStateException: Could not execute method of the activity
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.view.View$1.onClick(View.java:3597)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.view.View.performClick(View.java:4202)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.view.View$PerformClick.run(View.java:17340)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.os.Handler.handleCallback(Handler.java:725)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.os.Looper.loop(Looper.java:137)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.app.ActivityThread.main(ActivityThread.java:5039)
01-16 11:50:12.833: E/AndroidRuntime(799):  at java.lang.reflect.Method.invokeNative(Native Method)
01-16 11:50:12.833: E/AndroidRuntime(799):  at java.lang.reflect.Method.invoke(Method.java:511)
01-16 11:50:12.833: E/AndroidRuntime(799):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-16 11:50:12.833: E/AndroidRuntime(799):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-16 11:50:12.833: E/AndroidRuntime(799):  at dalvik.system.NativeStart.main(Native Method)
01-16 11:50:12.833: E/AndroidRuntime(799): Caused by: java.lang.reflect.InvocationTargetException
01-16 11:50:12.833: E/AndroidRuntime(799):  at java.lang.reflect.Method.invokeNative(Native Method)
01-16 11:50:12.833: E/AndroidRuntime(799):  at java.lang.reflect.Method.invoke(Method.java:511)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.view.View$1.onClick(View.java:3592)
01-16 11:50:12.833: E/AndroidRuntime(799):  ... 11 more
01-16 11:50:12.833: E/AndroidRuntime(799): Caused by: java.lang.SecurityException: Admin ComponentInfo{com.marakana.android.devicepolicydemo/com.marakana.android.devicepolicydemo.DemoDeviceAdminReceiver} did not specify uses-policy for: disable-camera
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.os.Parcel.readException(Parcel.java:1425)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.os.Parcel.readException(Parcel.java:1379)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.app.admin.IDevicePolicyManager$Stub$Proxy.setCameraDisabled(IDevicePolicyManager.java:1700)
01-16 11:50:12.833: E/AndroidRuntime(799):  at android.app.admin.DevicePolicyManager.setCameraDisabled(DevicePolicyManager.java:1345)
01-16 11:50:12.833: E/AndroidRuntime(799):  at com.marakana.android.devicepolicydemo.DevicePolicyDemoActivity.onClick(DevicePolicyDemoActivity.java:62)

我该如何解决?

2 个答案:

答案 0 :(得分:3)

如果您应用的上一版本未包含“禁用摄像头”政策,则应在更新应用时明确显示设备政策协议屏幕。只有在用户接受“禁用摄像头”策略后,该应用才会拥有禁用摄像头的权限。

答案 1 :(得分:2)

我认为你需要添加

<uses-policies>
    <disable-camera />
</uses-policies>
清单文件中的