SurfaceView SurfaceHolder MediaPlayer Service BroadcastReceiver KeyguardManager PowerManager
思路:启动一个服务,监听灭屏广播,当收到广播的时候,点亮屏幕,禁用锁屏,调用使用SurfaceView播放视频。
1.启动一个服务
Intent intent = new Intent();
intent.setClass(this,LockService.class);
startService(intent);
2.LockService onCreate中注册监听ACTION_SCREEN_OFF
final IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(mReceiver, filter);
3.LockService 的内部监听类
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (Intent.ACTION_SCREEN_OFF.equals(action)) {
Log.d("yzy","screen_off...");
if(HelloActivity.isScreenOff == false){
wakeUpScreen();
Intent intent1 = new Intent();
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.setClass(LockService.this, HelloActivity.class);//启动屏保界面
startActivity(intent1);
HelloActivity.isScreenOff = true;
}
}
}
};