Breaking News
Home / Android / Android Snippets / How to acquire and release the wakeup lock in Android?

How to acquire and release the wakeup lock in Android?

Example Use case:

Let’s say an Android phone is in sleep mode and upon receiving a push notifications we want the phone to wake up (come out of sleep mode) and act upon (display etc.) the notification. In this case on receiving the notification which invokes the notification handler, we can wake up the processor by acquiring the Wakeup lock, act on the notification and then release the lock. The following code snippet shows the same:

In order to get the lock, make sure you declare the following permission in the Android Manifest.

<!– Keeps the processor from sleeping when a message is received. –>
    <uses-permission android:name=”android.permission.WAKE_LOCK” />[pb_builder]

Check Also

How to get a list of Calendars names in Android?

Get a list of installed calendar in an Android device is relatively easy. This involves …

Advertisment ad adsense adlogger