SurfaceView SurfaceHolder MediaPlayer Service BroadcastReceiver KeyguardManager PowerManager
思路:啟動一個服務,監聽滅屏廣播,當收到廣播的時候,點亮屏幕,禁用鎖屏,調用使用SurfaceView播放視頻。
1.啟動一個服務
<service Android:name=".LockService" >
<intent-filter>
<category android:name="android.intent.category.default" />
</intent-filter>
</service>
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;
}
}
}
};