自动解锁并唤醒屏幕

需求: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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值