Questions tagged [android-powermanager]

Tag for Android PowerManager questions - class, that gives you control of the power state of the device.

This class 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.

Useful links

70 questions
3
votes
1 answer

How to prevent app being killed in background?

On my Huawei P20 Lite (Android 9), there is a setting Power usage details -> app launch -> "Manage automatically". With this setting enabled, I noticed that the OS sometimes kills my app when it is in background. The app acts as a streaming…
matdev
  • 4,115
  • 6
  • 35
  • 56
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
2 answers

PARTIAL_WAKE_LOCK does not work

I created a new project with target API 15 (ICS) with empty Activity. I added permission to manifest: I added code to onCreate(): @Override protected void onCreate(Bundle…
c0dehunter
  • 6,412
  • 16
  • 77
  • 139
3
votes
2 answers

Continue Download in android even after the device is locked

How to continue download task even when after the device is locked (pressing the power button). I tried installing an app from the play store, and during its download i locked the device, but it still continues to download without any interruption…
3
votes
1 answer

What happens to connection with BLE device when Android goes in sleep mode

What happens to connection with BLE device connection when Android goes in sleep mode? So if application establishes a connection with BLE device and then Android goes sleep, will the connection be maintained? Will the application be informed about…
3
votes
1 answer

Is there any way to obtains CMOS Status?

I would like to know, 1) Is there any way to access status of CMOS Battery in android(specially in Sumsung)? Or 2) Is there any API or some classes/Methods which can access CMOS battery? I didn't find anything on this subject... Thank you guys !
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
1 answer

Right way to use wake lock (minimizing battery use) to process incoming SMS's

Let me start by admitting that I am learning (or struggling to learn) Android, while also doing something that appears to be somewhat challenging. While I think I have understood the basic usage of BroadcastReceivers and I can use one to receive…
3
votes
2 answers

What can android listen for while asleep?

I can't find a list of events that can be listened for while a device is sleeping. For example, it is possible to use LocationListener while asleep. My goal is to detect when a user is in his car by at least one of the following methods, which…
Jodes
  • 14,118
  • 26
  • 97
  • 156
2
votes
1 answer

Controlling the AOSP power-reporting functionality from new code

In the Android Open Source Project, where would I add/override the code which tells Android about the battery level and AC power? I need to poll a component on an i2c bus to get this information, on my board, and pass it to Android.
fadedbee
  • 42,671
  • 44
  • 178
  • 308
2
votes
0 answers

Qt Android Service : How to keep service running when screen is turned off + USB cable not connected?

Why doesn't the service work all the time in the background when the screen is off + USB not connected? Using Qt, I created a test android service that uses QTimer to issues Push-notifications every 5-seconds. I did this to monitor whether the…
Mena
  • 3,019
  • 1
  • 25
  • 54
2
votes
1 answer

Play sound on power button pressed in android

I am working on an app in which "when my app is running and user presses power button" to lock the phone, then before locking it should play a sound. I have searched for how to do this on SO on following links but didn't get any working…
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

Create alarm clock on android lollipop

I'm creating an alarm clock. To set the date and time, I use AlarmManager: AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = PendingIntent.getBroadcast(context, id, intent, …
2
votes
1 answer

Android: How to get Battery level status more accurately?

I want to get android battery info with more accuracy. I've found some code which gives battery level and scale but it isn't helping me out much. int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale =…