battery

battery status on ACTION_POWER_CONNECTED

跟風遠走 提交于 2020-01-04 14:29:05
问题 I'm just wondering if is there any possibility to obtain battery status in broadcast receiver class that fires on ACTION_POWER_CONNECTED? Documentation suggest not, but it is always worth to ask :) Cheers Ray 回答1: Call registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)) . The Intent that is returned is the last-broadcast ACTION_BATTERY_CHANGED broadcast, which has your battery status in its extras (see BatteryManager for the keys). If you determine that you are calling it

Is there a way to get battery info (status, plugged in, etc) without reading a proc/sys file on linux?

核能气质少年 提交于 2020-01-03 15:21:28
问题 I want to get information about the battery in C on linux. I don't want to read or parse any file! Is there any low-level interface to acpi/the kernel or any other module to get the information I want to have? I already searched the web, but every question results in the answer "parse /proc/foo/bar". I really don't want to do this because I think, low-level interfaces won't change as fast as Files do. best regards. 回答1: You might be looking for UPower: http://upower.freedesktop.org/ This is a

Getting battery status from a service in Android

跟風遠走 提交于 2020-01-03 03:28:29
问题 I am developing an app for which I need to monitor the remaining battery percentage from a service. Can anybody tell me how to do it? I found some sample codes that are getting the battery status from an activity, not from service. Thanks. 回答1: Use ACTION_BATTERY_CHANGED. It is called every time the battery value changes. See the code below to see how it is done: public void onCreate() { this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); } private

getting battery level at android widget

若如初见. 提交于 2020-01-01 08:56:28
问题 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. 回答1: hackbod gave the solution at the comments: " use

Get battery level in Java

白昼怎懂夜的黑 提交于 2020-01-01 07:08:09
问题 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 回答1: 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

Does the accelerometer drain battery on Android Wear? (Android watch)

折月煮酒 提交于 2019-12-30 05:09:25
问题 I'm creating an Android Wear app that tries to detect some of the hand movements, to do it, I need to continuously monitor the accelerometer output . I'm wondering how it will affect the battery life. For phones, I know that there are methods like "disable accelerometer while screen is turned off" to save battery, but what's the battery cost in case of watches? Since Android watch can count your steps and it turns on the screen when you face it towards your face, I believe the accelerometer

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

非 Y 不嫁゛ 提交于 2019-12-28 03:38:10
问题 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 UUID Battery_Service_UUID = UUID.fromString("0000180F-0000-1000-8000-00805f9b34fb"); private static final UUID Battery_Level_UUID = UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb"); public void getbattery() { BluetoothGattService batteryService =

Battery status API in macOS?

本小妞迷上赌 提交于 2019-12-27 17:30:35
问题 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. 回答1: 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

Creating a temperature-sensing Android app that runs in the background after activation

早过忘川 提交于 2019-12-25 04:16:31
问题 I am developing an Android application that will keep track of the temperature of the battery of the phone. When the temperature of the battery exceeds some certain value, another activity will then give an alert which is an alarm. How can I let my application keep track of the temperature of the battery and send that info to another activity (an alarm system) to compare values and determine whether to set off the alarm? I am using Eclipse and Android 4.1.2. 回答1: There's a sensor. For Android

iPhone Battery Percentage on OS X (Cocoa) like iTunes

孤人 提交于 2019-12-24 13:12:24
问题 I'm trying to find a SDK or anything in Cocoa for OS X that will detect when an iPhone is connected and will show the battery percentage of the iPhone just like iTunes where it shows you how much your phone is charged (the little battery icon). So if anyone can tell me if there is something like this i thank you in advance. (BTW this has to be for OS X) 回答1: Have a look at https://bitbucket.org/tristero/mobiledeviceaccess Specifically, getMobileGestaltValue: using the key