是否有可能在30秒内打开和关闭设备的屏幕背光,使其看起来像闪烁的屏幕?
public class blinking extends TimerTask {
@Override
public void run() {
PowerManager powerMan = (PowerManager) *getSystemService*(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerMan.newWakeLock(
PowerManager.SCREEN_DIM_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "wakelockTag");
boolean screenOn = false;
for (int i = 0; i < 30; i++) {
if (screenOn) {
wakeLock.acquire();
screenOn = false;
} else {
wakeLock.release();
screenOn = true;
}
}
}
}
在我的Activity类中使用此代码(用于调用Blinking类):
Timer mTimer = new Timer();
mTimer.schedule( new blinking(), 30000 );
答案 0 :(得分:1)
在班上试试这个:
创建电源管理器参数
PowerManager powerMan = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerMan.newWakeLock(
PowerManager.SCREEN_DIM_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "wakelockTag");
调用计时器
Timer timer = new Timer();
timer.schedule( new FlashingTimerTask(), 30000 );
对于Timer任务:
public class FlashingTimerTask extends TimerTask{
@Override
public void run() {
boolean screenOn = false;
for (int i = 0; i < 30; i++) {
if (screenOn) {
wakeLock.acquire();
screenOn = false;
} else {
wakeLock.release();
screenOn = true;
}
}
}
}