Questions tagged [battery]

A battery is a portable electrical power source which is often used in mobile devices.

An electric battery is a device consisting of one or more electrochemical cells that convert stored chemical energy into electrical energy.

Each cell contains a positive terminal, or cathode, and a negative terminal, or anode. Electrolytes allow ions to move between the electrodes and terminals, which allows current to flow out of the battery to perform work.

813 questions
113
votes
10 answers

Get battery level and state in Android

How can I get battery level and state (plugged in, discharging, charging, etc)? I researched the developer docs and I found a BatteryManager class. But it doesn't contain any methods, just constants. How do I even use it?
Mohit Deshpande
  • 48,747
  • 74
  • 187
  • 247
74
votes
9 answers

Is my Android App Draining Battery?

I'm developing a game for Android. It uses a surface view and uses the sort of standard 2D drawing APIs provided. When I first released the game, I was doing all sorts of daft things like re-drawing 9-patches on each frame and likewise with text. I…
Tom R
  • 5,825
  • 9
  • 33
  • 41
42
votes
6 answers

Get battery level before broadcast receiver responds for Intent.ACTION_BATTERY_CHANGED

I have a broadcast receiver in my program to get react to the battery level like so: private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent intent) { int level =…
stealthcopter
  • 13,374
  • 11
  • 61
  • 80
42
votes
3 answers

Socket connections and Polling. Which is a better solution in terms of battery life?

So... I'm making an application for Android. The application needs to send and receive realtime chat data (needs to be a socket) but it also needs to send commands (which don't as the client knows when it is sending something). I need to know what…
shadrx
  • 921
  • 1
  • 8
  • 22
31
votes
4 answers

Battery status API in macOS?

How can I read the status of the battery on my MacBookPro from my own application? Googling has so far only revealed APIs for device drivers to handle power events - there's nothing about user-land processes accessing this information. thanks.
Alnitak
  • 313,276
  • 69
  • 379
  • 466
27
votes
8 answers

Getting the battery current values for the Android Phone

I am trying to collect power usage statistics for the Android G1 Phone. I am interested in knowing the values of Voltage and Current, and then able to collect statistics as reported in this PDF. I am able to get the value of Battery voltage…
Chintan Parikh
  • 609
  • 1
  • 5
  • 14
19
votes
1 answer

Will a Handler postDelayed not being fired when CPU sleeps?

I have an activity with some Handlers that are being executed at intervals no more than 5 minutes. The activity is launched from a BroadcastReceiver and may be launched with the screen off waiting for the user to grab the phone and get the user…
18
votes
1 answer

Websockets versus GCM under Android: battery usage?

I need to maintain an open, two-way communication channel between an Android app and an external server. I know that I can use GCM for this, but for various reasons that don't pertain to Android, itself, I would like to use websockets, if at all…
17
votes
3 answers

how to get the battery usage details of installed apps?

Using this code, I can find the battery level of the phone: int level = battery.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = battery.getIntExtra(BatteryManager.EXTRA_SCALE, -1); float percent = (level / (float)scale) * 100; But how do I…
17
votes
3 answers

How can I find out how much battery my Android app consumes on user's devices?

I am writing an app to evaluate the feasibility of a Bluetooth P2P network on Android. I noticed that on a Galaxy Nexus, it uses very little battery, while on a Nexus S, it drains the battery very quickly. This is directly caused by high CPU load…
Jan Schejbal
  • 3,820
  • 16
  • 38
16
votes
2 answers

PubNub long polling vs sockets - mobile battery life

I recently began using PubNub in my iOS app, and am very happy with it. However, I have been looking at the other options available, such as Pusher and Realtime.co, which use Websockets. PubNub, on the other hand, uses long polling. I have done my…
user1032657
  • 2,371
  • 6
  • 25
  • 34
15
votes
1 answer

How to get the battery level after connect to the BLE device?

I am developing an application where I have to connect to Bluetooth device on Android 4.3. And I want to get the battery level by using Battery_Service and Battery_Level. public class BluetoothLeService extends Service { private static final…
15
votes
2 answers

Understanding the Android "Radio State Machine" for better battery life

On the Android documentation page Optimizing Downloads for Efficient Network Access, the gist is that "waking up the radio is bad", "batch your transfers" or "piggyback on GCM". That article leaves some inner working principles for the curious: It…
kizzx2
  • 17,547
  • 14
  • 72
  • 81
15
votes
7 answers

How to get real time battery level on iOS with a 1% granularity

I'm using this function to get current battery level of device: [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; UIDevice *myDevice = [UIDevice currentDevice]; [myDevice setBatteryMonitoringEnabled:YES]; double batLeft = (float)[myDevice…
cat
  • 327
  • 1
  • 5
  • 14
14
votes
3 answers

Getting Battery Health Information on iOS

There are currently apps in the app-store (so it does not require jailbreak) that tell you : Exact percentage value of battery level you have on your iPhone. I have tried Apple's official Code Sample, although it tells you when your iPhone is…
ShayanK
  • 1,205
  • 1
  • 13
  • 25
1
2 3
54 55