0

In my application, user starts the service it is open and it is called every 5 minutes. it works fine. But I want to unlock automatically (call WAKE_LOCK ) whenever the service is called i.e. every 5 minutes. How can I achieve this?

Any body please help me...

Edit 1#

private void handleIntent(Intent intent) { // obtain the wake lock 
        PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); 
        mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, NAME); 

        mWakeLock.acquire();
    }
Android_dev
  • 320
  • 1
  • 7
  • 26

1 Answers1

0

You have to use the AlarmManager for that.

Set up of the alarm and its receiver : Notification activity called by AlarmManager NOT to pop up when app is closed

Then you have to convert your service to a wakeful intent service and then call WakefulIntentService.sendWakefulWork(context, YourService.class); inside onReceive(context)

At least this was the way to go - the latest android platform seems to support this (kind of) out the box : https://developer.android.com/reference/android/support/v4/content/WakefulBroadcastReceiver.html

Community
  • 1
  • 1
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361