0
我想通過編程解鎖我的Android手機。我用下面的代碼爲Android 6.0,但是它有一些問題如何通過代碼解鎖Android 6.0
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km .newKeyguardLock("MyKeyguardLock");
kl.disableKeyguard();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
因爲KeyguardLock已過時,因此我用下面的代碼
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
,但它有一個錯誤
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6363)
at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:874)
at android.view.View.requestLayout(View.java:17483)
at android.view.View.setLayoutParams(View.java:11478)
at android.view.WindowManagerGlobal.updateViewLayout(WindowManagerGlobal.java:305)
at android.view.WindowManagerImpl.updateViewLayout(WindowManagerImpl.java:91)
at android.app.Activity.onWindowAttributesChanged(Activity.java:2596)
at android.support.v7.view.WindowCallbackWrapper.onWindowAttributesChanged(WindowCallbackWrapper.java:108)
at android.view.Window.dispatchWindowAttributesChanged(Window.java:852)
at com.android.internal.policy.impl.PhoneWindow.dispatchWindowAttributesChanged(PhoneWindow.java:4252)
at android.view.Window.setFlags(Window.java:825)
at android.view.Window.addFlags(Window.java:771)
如何要解決這個問題?其次,如果我的手機被密碼鎖定,我該如何解鎖它?謝謝
謝謝。你能編輯所有Android版本的權限嗎?我在Android 5.0測試,它有一個更多的問題,手機解鎖,但屏幕不亮 – Jame
搜索股票溢出如何解鎖設備..你會得到答案 –
我在stackoverflow中搜索並獲得上述代碼。它解鎖我的手機,但沒有喚醒燈光 – Jame