forked from ybin/android_notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenBroadcastReceiver.java
More file actions
36 lines (31 loc) · 1.29 KB
/
ScreenBroadcastReceiver.java
File metadata and controls
36 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public class ScreenBroadcastReceiver extends BroadcastReceiver {
public static final String TAG = "ScreenBroadcastReceiver";
private PowerManager mPowerManager;
private PowerManager.WakeLock mWakeLock;
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "receive intent: " + intent.getAction());
mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
if(Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
Log.d(TAG, "light the screen on.");
mWakeLock = mPowerManager.newWakeLock(
PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
"ScreenBroadcastReceiver");
mWakeLock.acquire(5000);
}
if(Intent.ACTION_SCREEN_ON.equals(intent.getAction())) {
Log.d(TAG, "start video screen saver.");
Intent i = new Intent("zte.com.cn.action.videoscreensaver");
i.addCategory(Intent.CATEGORY_DEFAULT);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
if(mWakeLock != null && mWakeLock.isHeld()) {
Log.d(TAG, "Wake Lock released.");
// wake lock is released automatically after 5s,
// so, we do NOT need to release it.
// if wake lock is released too fast, android 4.1 is behave abnormally.
// mWakeLock.release();
}
}
}
}