Questions tagged [powermanager]

PowerManager is a class in the Android SDK that gives control of the power state of the device.

PowerManager is a class in the Android SDK that gives you control of the power state of the device.

Device battery life will be significantly affected by the use of this API. Do not acquire PowerManager.WakeLocks unless you really need them, use the minimum levels possible, and be sure to release them as soon as possible.

You can obtain an instance of this class by calling Context.getSystemService().

The primary API you'll use is newWakeLock(). This will create a PowerManager.WakeLock object. You can then use methods on the wake lock object to control the power state of the device.

Reference page: http://developer.android.com/reference/android/os/PowerManager.html

109 questions
5
votes
2 answers

PowerManager.WakeLock on Android Devices

i am trying to implement an WakeLock in my Android App. I have the following code in my onCreat(): pm = (PowerManager) getSystemService(Context.POWER_SERVICE); myWakeLock = pm.newWakeLock(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,"WakeLock for…
Benedikt Bock
  • 1,007
  • 15
  • 37
4
votes
1 answer

How to programmatically determine if an Android app is put to sleep on Samsung Galaxy?

Samsung Galaxy has the feature to put apps to sleep - which to my understanding is not the same as battery optimization for apps. I need to programmatically check if an app is configured to sleep so I can properly warn the user about this and the…
Seb T
  • 795
  • 8
  • 16
4
votes
1 answer

How to use PowerManager.ACQUIRE_CAUSES_WAKEUP

How can I use ACQUIRE_CAUSES_WAKEUP? ACQUIRE_CAUSES_WAKEUP must be used with another wakelock or you risk an error: java.lang.IllegalArgumentException: Must specify a valid wake lock level. However, FULL_WAKE_LOCK, SCREEN_DIM_WAKE_LOCK, and…
Domen Jakofčič
  • 626
  • 1
  • 8
  • 24
4
votes
1 answer

How to wake up an Android Embedded Board from Suspend by using a GPIO

I am currently working on porting Android 4.4 (Kitkat) on an embedded system (Freescale i.MX6 based). In order to start my development, I used a few development kits (Wandboard, Boundary Device's BD-SL). While working on the power management of my…
gfrigon
  • 2,237
  • 2
  • 23
  • 32
3
votes
0 answers

Music Player Stuck partial wake locks (background)

I have an android music player and I see a "Stuck partial wake locks (background)" in the Play Console. I'm not sure how to fix it. I search my code and the only code that I find is the following when I initialized the player. …
3
votes
0 answers

memory leak in android.os.PowerManager

I have identified memory leak, with following report from Eclipse Memory Analyzer mBuffer android.graphics.Bitmap '- mDrawBitmap com.bilickib.android.charts.PieChartView '- pieChartView mine.PieChartFragment '- mCurrentPrimaryItem…
3
votes
3 answers

How to bring application from background to foreground via BroadcastReceiver

I have two classes which are MainActivity and MyBroadcastReceiver. BroadcastReceiver detects whether phone screen is on or off. My desire is to launch my application whenever screen lock is released. I mean that I want to bring my application to the…
gokhanakkurt
  • 4,935
  • 4
  • 28
  • 39
2
votes
1 answer

Turn off screen from Android service

How can I turn off screen in Android from a Service? I tried with a wakelock (with permission in manifest) but it doesn't work (screen doesn't turn off). P.S. I don't want to use a dummy activity which set brightness to 0. public class Servizio…
Angelo Tricarico
  • 1,333
  • 1
  • 19
  • 36
2
votes
0 answers

Android - How to detect "Power Save mode" in Huawei or other devices?

I’m making some optimizations on my app for devices with "power saving mode" enabled. Here's the sample code: import android.content.Context; import android.os.PowerManager; import android.provider.Settings; //for MIUI private boolean…
2
votes
1 answer

Purpose of WakeLock in modern Android?

I'm having a hard time understanding the purpose of WakeLock in modern versions of Android, after the introduction of Doze and Foreground Services. It appears as if WakeLocks are pretty much legacy as this point (although not marked as deprecated),…
2
votes
1 answer

Android PowerManager isInteractive() vs isScreenOn() bug?

I am attempting to determine whether or not the screen is on using the following code: private void isScreenOn() { if (Build.VERSION.SDK_INT >= 20) { if (mPowerManager.isInteractive()) { //Do stuff …
neonDion
  • 2,278
  • 2
  • 20
  • 39
2
votes
1 answer

How can I access IDeviceIdleController instance in Android M

I'm exploring the changes in Android M preview release 1. Specifically, I want to know if I can programmatically check to see if my app is whitelisted from Doze and App Standby mode. I basically want the result of "adb shell dumpsys deviceidle". I…
2
votes
0 answers

Screen is not sleeping when touching the screen

I am trying to show a pop-up on the lock-screen. And also after a interval of time the screen have to go to sleep. It is working with acquiring the wakelock and releasing it after a period of time on a Activity. But the problem is if the screen is…
J.R
  • 2,113
  • 19
  • 21
2
votes
1 answer

Call setPowerSaveMode of PowerManager class with reflection

I will call a method of the public final class PowerManager with @hide annotation. the method is: /** * Set the current power save mode. * * @return True if the set was allowed. * * @see #isPowerSaveMode() * * @hide */ public boolean…
Tenaciousd93
  • 3,438
  • 4
  • 33
  • 56
2
votes
1 answer

switch off/on screen on PARTIAL_WAKE_LOCK

I'm using this code to enter in PARTIAL_WAKE_LOCK mode: PowerManager pm = PowerManager.getSystemService(Context.POWER_SERVICE); screenWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, …