删除新的守卫洛克

时间:2015-02-10 18:05:06

标签: android locking lockscreen keyguard keyguardlock

Android新手, 目前正在使用锁屏应用程序。在我的应用程序中,当我在我的Xperia手机中运行时,异常发生..我在函数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)

1 个答案:

答案 0 :(得分:0)

您需要将此权限添加到Android清单:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>