2013-01-16 43 views
0

我寫過這些代碼;禁用相機但不能正常工作

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

我認爲你需要在清單文件中添加

<uses-policies> 
    <disable-camera /> 
</uses-policies> 

+0

我已經這樣做了。 – user1983122

+0

@ user1983122,你把它放在設備管理節點內嗎? –

+0

如果你說device-admin.xlm,答案是肯定的 – user1983122

3

如果您的應用的先前版本不包含「禁用攝像頭」策略,則應在更新應用時明確顯示設備策略協議屏幕。只有在用戶接受「禁用相機」政策後,該應用程序纔有權禁用相機。