删除线中的newKeyguardLock
问题描述:
Android中的新功能, 目前正在使用锁定屏幕应用程序。在我的应用程序中,当我在我的Xperia手机中运行它时,会发生异常。并且我在函数newKeyguardLock()中发现了一条删除线。我认为这是问题。任何人都可以帮助我解决此问题。 我的代码: -删除线中的newKeyguardLock
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
我的日志: -
02-10 23:16:39.597 20836-20836/it.screen.lock.monuz.truncar E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{it.screen.lock.monuz.truncar/it.screen.lock.monuz.truncar.LockScreenActivity}: java.lang.SecurityException: Requires DISABLE_KEYGUARD permission
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invok`enter code here`e(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: Requires DISABLE_KEYGUARD permission
at android.os.Parcel.readException(Parcel.java:1436)
at android.os.Parcel.readException(Parcel.java:1389)
at android.view.IWindowManager$Stub$Proxy.disableKeyguard(IWindowManager.java:1541)
at android.app.KeyguardManager$KeyguardLock.disableKeyguard(KeyguardManager.java:72)
at it.screen.lock.monuz.truncar.LockScreenActivity.onCreate(LockScreenActivity.java:32)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
答
你需要这个权限添加到Android清单:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>