battery

Battery status in OSX?

三世轮回 提交于 2019-11-26 22:11:05
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. Ben Gottlieb You'll want to use IOKit for this, specifically the IOPowerSources functions . You can use IOPSCopyPowerSourcesInfo() to get a blob, and IOPSCopyPowerSourcesList() to then extract a CFArray out of that, listing the power sources. Then use IOPSGetPowerSourceDescription() to pull out a dictionary (see IOPSKeys.h for the contents of the

I can't receive broadcast on battery state change?

北城余情 提交于 2019-11-26 21:47:28
问题 I am having the exact same problem as this post: Battery broadcast receiver doesn't work. But it seems no one has answered that question. Here is my BroadcastReceiver: public class BatteryLevelReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Log.v("plugg", "plug change fired"); Toast.makeText(context, " plug change fired", Toast.LENGTH_LONG).show(); } And here is my AndroidManifest.xml: <receiver android:name=".ReceversAndServices

Create “Battery usage” intent android

流过昼夜 提交于 2019-11-26 21:37:57
问题 On my nexus one, there is a handy app reachable from Settings > About Phone > Battery use. I'd like to StartActivity() that app from one of my Activities. I can see in the log that when Settings runs it, this intent is logged: Starting activity: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.fuelgauge.PowerUsageSummary } I'm having trouble relating that to something in Android Java source. I can't even find "fuelgauge" in the GIT source. Can anyone point me to the right

Is my Android App Draining Battery?

一世执手 提交于 2019-11-26 18:50:14
问题 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 have since optimised much of this by drawing to Bitmap objects and drawing them each frame, only re-drawing onto the Bitmap objects when required. I've received complaints about battery drain before, and following my modifications I'd like to know

Getting the battery current values for the Android Phone

怎甘沉沦 提交于 2019-11-26 18:37:49
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 through registering for an intent receiver to receive the Broadcast for ACTION_BATTERY_CHANGED. But the problem is that Android does not expose the value of current through this SDK interface. One way I tried is via sysfs interface, where I can view the battery current value from adb shell, using the following command $cat /sys/class/power_supply/battery

Detecting the device being plugged in

白昼怎懂夜的黑 提交于 2019-11-26 17:46:57
问题 I would like to be able to detect whether or not the device is plugged in. I would like to be able to just query that the same way we can do for the connectivity state. Is that possible or do I need to create a broadcast receiver that listens for the battery events? 回答1: Apparently the ACTION_BATTERY_CHANGED is a "sticky broadcast" which means you can register for it and receive it any time after it has been broadcast. To get the plugged state you can do something like: public void onCreate()

ACTION_BATTERY_CHANGED firing like crazy

半世苍凉 提交于 2019-11-26 16:27:53
问题 Okay, so I'm working on an AppWidget that checks the battery level and displays it on a TextView. My code looks like this: public class BattWidget extends AppWidgetProvider { private RemoteViews views = new RemoteViews("com.nickavv.cleanwidgets", R.layout.battlayout); @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int appWidgetIds[]) { final int N = appWidgetIds.length; context.getApplicationContext().registerReceiver(this,new IntentFilter(Intent.ACTION

Get battery level before broadcast receiver responds for Intent.ACTION_BATTERY_CHANGED

淺唱寂寞╮ 提交于 2019-11-26 08:00:09
问题 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 = intent.getIntExtra(\"level\", 0); // do something... } } registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); However this code has to wait for the battery status to be updated so if you have a GUI element that needs to be set

Get battery level and state in Android

北慕城南 提交于 2019-11-26 01:14:13
问题 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? 回答1: Here is a code sample that explains how to get battery information. To sum it up, a broadcast receiver for the ACTION_BATTERY_CHANGED intent is set up dynamically, because it can not be received through components declared in manifests, only by explicitly registering

Get battery level and state in Android

淺唱寂寞╮ 提交于 2019-11-25 21:02:20
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? Here is a code sample that explains how to get battery information. To sum it up, a broadcast receiver for the ACTION_BATTERY_CHANGED intent is set up dynamically, because it can not be received through components declared in manifests, only by explicitly registering for it with Context.registerReceiver() . public class Main extends Activity { private TextView batteryTxt;