这里缺少什么?我想从睡眠中唤醒设备,但没有任何反应。我当然不想阻止睡觉。
final Handler handler = new Handler();
Runnable runable = new Runnable() {
@Override
public void run() {
try{
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire();
wl.release();
Log.v("INTERVAL: ", "NOW" );
handler.postDelayed(this, 5000);
}
catch (Exception e) {
// TODO: handle exception
}
}
这是日志:正如它被问到的那样;希望有助于找出你需要的东西
08-11 21:09:54.190: D/DateTimeIntentReceiver(2131): com.android.systemui.statusbar.phone.COLLAPSED is received, dialog_state : false, mDialog : null
08-11 21:09:54.190: E/TabletStatusBar(3982): closing mini mode apps panel
08-11 21:09:54.200: V/yamaha::media::VolumeCtrl(3841): VolumeCtrl::createVolume()
08-11 21:09:54.200: D/yamaha::media::VolumeCtrl(3841): Dir0 : AP Playback Music SP (0001h)
08-11 21:09:54.200: D/yamaha::media::VolumeCtrl(3841): Dir0Att : AP Playback Music SP (0001h)
08-11 21:09:54.200: D/yamaha::media::VolumeCtrl(3841): DacMaster : AP Playback Music SP (0001h)
08-11 21:09:54.200: D/yamaha::media::VolumeCtrl(3841): Sp : AP Playback Music SP (FE81h)
08-11 21:09:54.200: V/yamaha::media::UserDep(3841): UserDep::getRouteInfo(output: audioengine=0, devices=00000002h
08-11 21:09:54.200: V/yamaha::media::UserDep(3841): incall: onoff=0, devices=00000000h
08-11 21:09:54.200: V/yamaha::media::UserDep(3841): capture: onoff=0, devices=00100000h, audioSource=1
08-11 21:09:54.200: V/yamaha::media::UserDep(3841): playback: audio_onoff=1, line_onoff=0)
08-11 21:09:54.200: V/yamaha::media::UserDep(3841): Playback[Audio], Output[dev:DAC, NonAE]
08-11 21:09:54.200: V/yamaha::media::UserDep(3841): editDacDst(devices=2h) HPOUT Off
08-11 21:09:54.200: V/yamaha::media::UserDep(3841): editDacDst(devices=2h) RCOUT Off
08-11 21:09:54.200: V/yamaha::media::UserDep(3841): editDacDst(devices=2h) LINEOUT1 Off
08-11 21:09:54.200: V/yamaha::media::VolumeCtrl(3841): VolumeCtrl::setVolume()
08-11 21:09:54.200: D/yamaha::media::VolumeCtrl(3841): VolumeCtrl::setVolume() FM Playback: Ready
08-11 21:09:54.200: D/yamaha::media::VolumeCtrl(3841): VolumeCtrl::setVolume() VoiceCall: Ready
08-11 21:09:54.215: I/SurfaceFlinger(1721): id=521(69) createSurface 0x2f924 (1280x752),1 flag=0, Keyguard
08-11 21:09:54.215: V/WindowManager(3871): rotationForOrientationLw(orient=4, last=0); user=0 USER_ROTATION_LOCKED mLidOpen=-1 mDockMode=0 mHdmiPlugged=false mAccelerometerDefault=0 sensorRotation=-1
08-11 21:09:54.235: D/KeyguardUpdateMonitor(3871): handleClockVisibilityChanged()
08-11 21:09:54.235: D/KeyguardViewMediator(3871): adjustStatusBarLocked: mShowing=true mHidden=false isSecure=true --> flags=0x1290000
08-11 21:09:54.235: V/LockPatternKeyguardView(3871): View com.android.internal.widget.TransportControlView@41523698 requested hide transports
08-11 21:09:54.240: D/LockPatternKeyguardView(3871): focused
08-11 21:09:54.240: I/TabletStatusBar(3982): DISABLE_CLOCK: yes
08-11 21:09:54.255: E/TabletStatusBar(3982): closing mini mode apps panel
08-11 21:09:54.265: I/ALSAModule(3841): Initialized ALSA PLAYBACK device hifi
08-11 21:09:54.290: D/KeyguardUpdateMonitor(3871): handleClockVisibilityChanged()
08-11 21:09:54.290: D/KeyguardViewMediator(3871): adjustStatusBarLocked: mShowing=true mHidden=false isSecure=true --> flags=0x1290000
08-11 21:09:54.510: E/DataRouter(1719): usb connection is true
08-11 21:09:54.510: E/DataRouter(1719): DSR is ON. Don't send DTR ON.
08-11 21:09:54.525: I/AudioPolicyManager(3841): stopOutput() output 1, stream 1, session 5715
08-11 21:09:54.550: I/AudioFlinger(3841): stop output streamType (0, 1) for 1
08-11 21:09:55.055: V/yamaha::media::VolumeCtrl(3841): VolumeCtrl::createVolume()
08-11 21:09:55.055: D/yamaha::media::VolumeCtrl(3841): Dir0 : AP Playback Music SP (0001h)
08-11 21:09:55.055: D/yamaha::media::VolumeCtrl(3841): Dir0Att : AP Playback Music SP (0001h)
08-11 21:09:55.055: D/yamaha::media::VolumeCtrl(3841): DacMaster : AP Playback Music SP (0001h)
08-11 21:09:55.055: D/yamaha::media::VolumeCtrl(3841): Sp : AP Playback Music SP (FE81h)
08-11 21:09:55.055: V/yamaha::media::UserDep(3841): UserDep::getRouteInfo(output: audioengine=0, devices=00000002h
08-11 21:09:55.055: V/yamaha::media::UserDep(3841): incall: onoff=0, devices=00000000h
08-11 21:09:55.055: V/yamaha::media::UserDep(3841): capture: onoff=0, devices=00100000h, audioSource=1
08-11 21:09:55.055: V/yamaha::media::UserDep(3841): playback: audio_onoff=1, line_onoff=0)
08-11 21:09:55.055: V/yamaha::media::UserDep(3841): Playback[Audio], Output[dev:DAC, NonAE]
08-11 21:09:55.055: V/yamaha::media::UserDep(3841): editDacDst(devices=2h) HPOUT Off
08-11 21:09:55.055: V/yamaha::media::UserDep(3841): editDacDst(devices=2h) RCOUT Off
08-11 21:09:55.055: V/yamaha::media::UserDep(3841): editDacDst(devices=2h) LINEOUT1 Off
08-11 21:09:55.055: V/yamaha::media::VolumeCtrl(3841): VolumeCtrl::setVolume()
08-11 21:09:55.055: D/yamaha::media::VolumeCtrl(3841): VolumeCtrl::setVolume() FM Playback: Ready
08-11 21:09:55.055: D/yamaha::media::VolumeCtrl(3841): VolumeCtrl::setVolume() VoiceCall: Ready
08-11 21:09:56.510: E/DataRouter(1719): usb connection is true
08-11 21:09:56.510: E/DataRouter(1719): DSR is ON. Don't send DTR ON.
08-11 21:09:57.655: I/ALSAModule(3841): Terminated ALSA PLAYBACK device hifi
08-11 21:09:58.035: V/yamaha::media::VolumeCtrl(3841): VolumeCtrl::createVolume()
08-11 21:09:58.035: V/yamaha::media::UserDep(3841): UserDep::getRouteInfo(output: audioengine=0, devices=00000002h
08-11 21:09:58.035: V/yamaha::media::UserDep(3841): incall: onoff=0, devices=00000000h
08-11 21:09:58.035: V/yamaha::media::UserDep(3841): capture: onoff=0, devices=00100000h, audioSource=1
08-11 21:09:58.035: V/yamaha::media::UserDep(3841): playback: audio_onoff=0, line_onoff=0)
08-11 21:09:58.035: V/yamaha::media::UserDep(3841): ALL Off
08-11 21:09:58.035: V/yamaha::media::VolumeCtrl(3841): VolumeCtrl::setVolume()
08-11 21:09:58.035: D/yamaha::media::VolumeCtrl(3841): VolumeCtrl::setVolume() FM Playback: Ready
08-11 21:09:58.035: D/yamaha::media::VolumeCtrl(3841): VolumeCtrl::setVolume() VoiceCall: Ready
08-11 21:09:58.510: E/DataRouter(1719): usb connection is true
08-11 21:09:58.510: E/DataRouter(1719): DSR is ON. Don't send DTR ON.
08-11 21:09:59.955: D/KeyguardViewMediator(3871): handleTimeout
08-11 21:09:59.955: D/PowerManagerService(3871): releaseWakeLockLocked flags=0x0 tag=keyguard myUID=1000 myPID=3871 myTID=3914
08-11 21:09:59.995: E/AlarmManagerService(3871): android_server_AlarmManagerService_set to type=3, 172800.000000000
08-11 21:09:59.995: V/AlarmManager(3871): waitForAlarm result :8
08-11 21:10:00.000: E/ActivityManager(3871): MANGAL broadcastIntentInPackageINTENT--->1:Intent { act=android.intent.action.TIME_TICK flg=0x40000004 (has extras) } packageName:android
08-11 21:10:00.000: E/ActivityManager(3871): MANGAL INTENT:Intent { act=android.intent.action.TIME_TICK flg=0x40000004 (has extras) }
08-11 21:10:00.000: E/ActivityManager(3871): MANGAL broadcastIntentInPackageINTENT--->2:Intent { act=android.intent.action.TIME_TICK flg=0x40000004 (has extras) }
答案 0 :(得分:0)
仅在作业完成时才应调用 wl.release(); 。如果你马上获得()和释放(),什么都不会发生。试试这个:
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
try{
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire();
//PUT HERE THE CODE YOU WANNA EXECUTE
wl.release();
}
catch (Exception e) {
// TODO: handle exception
} }
};
Log.v("INTERVAL: ", "NOW" );
handler.postDelayed(runnable, 5000);
另外,请确保将权限放在清单文件中:
<uses-permission android:name="android.permission.WAKE_LOCK" />