需求:TP不能用,需要调试一些东西,不能解锁。所以就写了个自动解锁的apk,安装运行即可自动解锁:
AutoUnlock.java
package com.example.autounlock;
import android.os.Bundle;
import android.os.PowerManager;
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.view.Menu;
public class AutoUnlock extends Activity {
private KeyguardManager mKeyguardManager = null;
private KeyguardLock mKeyguardLock = null;
private PowerManager mPm;
private PowerManager.WakeLock mWakeLock;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auto_unlock);
mPm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
mKeyguardLock = mKeyguardManager.newKeyguardLock("");
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
mWakeLock = mPm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
mWakeLock.acquire();
mKeyguardLock.disableKeyguard();
}
@Override
protected void onDestroy() {
mWakeLock.release();
//mKeyguardLock.reenableKeyguard();
super.onDestroy();
}
}
记得加入权限:
AndroidManifest.xml
<!-- 解锁的权限 -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
<!-- 亮屏的权限 -->
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>