battery

Total Battery Capacity in mAh of device Programmatically

℡╲_俬逩灬. 提交于 2019-12-04 05:15:46
I have tried powerprofile of Android....I have tried this code...but it gives me 1000 answer every time in all the devices... Is there any other way in android to get battery capacity... Eg.if mobile device capacity is 2000mAh it should return me 2000 public Double getBatteryCapacity() { Object mPowerProfile_ = null; double batteryCapacity = 0; final String POWER_PROFILE_CLASS = "com.android.internal.os.PowerProfile"; try { mPowerProfile_ = Class.forName(POWER_PROFILE_CLASS) .getConstructor(Context.class).newInstance(this); } catch (Exception e) { // Class not found? e.printStackTrace(); } try

getting battery level at android widget

岁酱吖の 提交于 2019-12-04 02:55:21
I wrote a widget for Android and I'm trying to get the battery level. I've tried using Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); but I get the error: "IntentReceiver components are not allowed to register to receive intents" Why? the ACTION_BATTERY_CHANGED is a sticky intent and I don't register a receiver (null in the first parameter). Any workaround? Thanks. hackbod gave the solution at the comments: " use getApplicationContext().registerReciever() " Ummmm...that feels like a bug. They must be doing the is-a- BroadcastRecevier

how to get the battery usage details of installed apps?

无人久伴 提交于 2019-12-03 23:03:37
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 get the battery usage details of apps installed on phone, including that of the screen, as shown in the image below? Sorry to disappoint you, but Android's power usage APIs are not public . so there is no official way to get what you want. But you can use reflection to access some private members and methods and make use of them. You can also check

Get battery level in Java

孤街醉人 提交于 2019-12-03 20:11:17
I would like to make a java app that shows the current battery level of my mac OS X. I have read get OS-level system information and was wondering how I could modify this to make it display the current % of battery Thanks I think you have two options. One is to use JNI to invoke native code to get the battery level. The other is to invoke the application pmset using System.exec in java and parse the output. I think the arguments to retrieve the battery level is pmset -g ps but you better check the man page You'll need to use the Mac OS X APIs: You can get information about power sources and

How does persistent tcp/ip connections preserve battery and lower bandwidth usage?

狂风中的少年 提交于 2019-12-03 17:08:05
In push notification mechanisms, like Apple's Push Notification Service, they use persistent IP connections. My question is, how does employing persistent connections save battery and bandwidth of a device? I am under the impression that since the connection is persistent, then the device always uses the WiFi or 3G/LTE radio. I know that through persistent connections, you will not waste bandwidth by not asking the server for changes when there is none, and instead the server will "push" to you these changes. But, I don't see how that preserves battery and bandwidth (since you have an always

Will a Handler postDelayed not being fired when CPU sleeps?

♀尐吖头ヾ 提交于 2019-12-03 16:54:13
问题 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 input, when this happens, the activity onPause() is called so for sure CPU is in sleep mode. I have not set the activity to turn screen on because I want to save as much battery as possible. I've tested it with my phone and works really well, while

How can I programmatically stop a notebook battery from charging

给你一囗甜甜゛ 提交于 2019-12-03 12:40:43
There is some easily available information on finding the status of a battery, or weather it's charging or not. (GetSystemPowerStatus API or System.Windows.Forms.SystemInformation.PowerStatus). I want to be able to stop a battery from charging based on some criteria, e.g. battery power > 20%. Is there an API to do this? I think it's impossible, because you have need some API for battery or battery charger. And this API can provide to you manufacturer of notebook and battery or battery charger support this. I honestly don't know, but I'd have a look at the APM or ACPI APIs. Other than that, the

Linux c++: apis vs /proc files?

非 Y 不嫁゛ 提交于 2019-12-03 11:53:27
Im working on an app to collect and send various bits of system info (partition space/free, laptop battery info, etc). Im not having much success getting this information in the form of direct c++ api.. though its all available via files in /proc (or similar). So - I'm wondering whether reading/parsing these files in my c++ app is the appropriate way to get this info or should I keep trying to discover APIs? ( NOTE: I am working with statvfs ). So far it looks like it's easier to gather this sort of info in Win32. Seems strange. It is best practice by far to stick with an API in the following

Android location aware notifications

人盡茶涼 提交于 2019-12-03 06:25:36
问题 I'm looking for best techniques for Location Aware notifications. My first try was to use LocationManager's addProximityAlert but it requires ACCESS_FINE_LOCATION (COARSE_LOCATION gives me a SecurityException) and keeps the GPS always ON and active (at least on Jelly Bean), which drains the battery very quickly. It also doesn't seems to respect the check only once every 4 minutes when the screen is asleep (addProximityAlert). I'm thinking to work with the PASSIVE_PROVIDER to gather other

Will a Handler postDelayed not being fired when CPU sleeps?

南楼画角 提交于 2019-12-03 05:11:26
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 input, when this happens, the activity onPause() is called so for sure CPU is in sleep mode. I have not set the activity to turn screen on because I want to save as much battery as possible. I've tested it with my phone and works really well, while screen is off all Handlers execute all the code they have to run. If I turn the screen on and off while