1.喚醒屏幕
private PowerManager.WakeLock mWakeLock;
private PowerManager mPowerManager;
@SuppressLint("InvalidWakeLockTag")
public void turnOnScreen() {
// turn on screen
try {
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
mWakeLock.acquire();
mWakeLock.release();
} catch (Exception e) {
}
}
2.在oncreate 中加入
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED //鎖屏顯示
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD //解鎖
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON //保持屏幕不息屏
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);//點(diǎn)亮屏幕
super.onCreate(savedInstanceState);
3.跳轉(zhuǎn)Activity時(shí)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
4.聲明權(quán)限
<!-- 彈出-->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<!-- 亮屏的權(quán)限 -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.USES_POLICY_FORCE_LOCK" />