0

What's missing in here? I want to wake up the device from sleep, but nothing happens. I certainly do not want to prevent sleeping.

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
            }
     }

this is the log: as it was asked; hope it helps to find out whatever you need

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) }
Shervin
  • 233
  • 1
  • 13

1 Answers1

0

The wl.release(); should be called only when the job is finished. If you acquire() and release() right away, nothing will happen. Try this:

 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);

Also, make sure you put the permission on your manifest file:

 <uses-permission android:name="android.permission.WAKE_LOCK" />
Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
  • A) tnx for the answer, B) I have the permission C) mmm, I tried your code, its not working. All I wanna do is just wake up the screen for now. – Shervin Aug 11 '14 at 16:56
  • actually this code 'prevents' the device from sleeping..it doesn't really wake up the screen. Where are you running it from? You should certainly need to run it from a BroadcastReceiver (scheduled to be executed (waking up the device)). You actually don't need a Handler when executing on the BroadcastReceiver...also You should probably check the types of locks: http://developer.android.com/reference/android/os/PowerManager.html – Alécio Carvalho Aug 11 '14 at 17:00
  • to tell you my exact goal; I want to wake up screen when my gps coords are reached to specific value, so I need to call a broadcast. right? – Shervin Aug 11 '14 at 17:09
  • Maybe you could consider using the http://developer.android.com/guide/topics/ui/notifiers/notifications.html waking up the screen out of the sudden might not be useful..imagine if the phone is in the pocket, nobody will see it. But with Notifications you can attach some sound and vibration and let the user decide whether or not open your app. See it here: http://developer.android.com/guide/topics/ui/notifiers/notifications.html – Alécio Carvalho Aug 11 '14 at 17:35