ボタンを押したときに画面(Android 4.4.2)を無効にしたい。デバイスをルート化せずにそれは可能ですか?以下のコードを試しましたが、動作しません (例外がスローされます)。
private DevicePolicyManager mDPM;
作成時:
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
ボタンリスナー:
mDPM.lockNow();
AndroidManifest.xml:
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
</intent-filter>
スタックトレース:
10-03 20:32:50.187 4172-4172/com.microchip.android.BasicAccessoryDemo_API12 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.microchip.android.BasicAccessoryDemo_API12, PID: 4172
java.lang.SecurityException: No active admin owned by uid 10175 for policy #3
at android.os.Parcel.readException(Parcel.java:1465)
at android.os.Parcel.readException(Parcel.java:1419)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.lockNow(IDevicePolicyManager.java:1594)
at android.app.admin.DevicePolicyManager.lockNow(DevicePolicyManager.java:1076)
at com.microchip.android.BasicAccessoryDemo_API12.PasswordActivity$1.onClick(PasswordActivity.java:209)
at android.view.View.performClick(View.java:4442)
at android.view.View$PerformClick.run(View.java:18471)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)