battery

Android BatteryManager Returns only 1

给你一囗甜甜゛ 提交于 2019-12-07 17:55:44
问题 I am attempting to read the state of the Android battery when my repeating alarm broadcaster is called I have the following setup: public class RepeatingAlarm extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Acquire the make of the device final String PhoneModel = android.os.Build.MODEL; final String AndroidVersion = android.os.Build.VERSION.RELEASE; // Grab the battery information int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);

Script to play a warning when battery level is under a threshold in MacOS

淺唱寂寞╮ 提交于 2019-12-07 17:25:00
问题 I am using a MacBook and the battery is unreliable. I am trying to find a script command that will enable the laptop to play a beep when the battery level is lower than a threshold. After some search and tests, I found a quick solution below: 1) I first create a file called check_battery with the following contents: ioreg -l | awk '$3~/Capacity/{c[$3]=$5}END{OFMT="%.3f";max=c["\"MaxCapacity\""]; bat= (max>0?100*c["\"CurrentCapacity\""]/max:"?"); printf("%d", bat)}' 2) I then created the

iPhone running periodical process in the background - battery optimized way

独自空忆成欢 提交于 2019-12-07 07:00:56
问题 I want to run a specific task in the background. This task takes few seconds to complete (it writes some GPS location data to a file). This task should run once every 1 hour. As I understand from the SDK, I do not have a way to INITIATE something in the background unless I run Location Services forever. When this service runs, it gives me an event from time to time, and I'm able to run my code during these calls. I tried it, and even with the minimal precision possible, my battery goes down

How to remove the battery icon in android status bar?

僤鯓⒐⒋嵵緔 提交于 2019-12-07 01:59:37
问题 I've removed the status bar which shows network, battery and time information in Android by take off the background image. But the icons are still there. Just wanna know how to remove the battery icon as well. Not for apps but for framework development. Thanks in advance. 回答1: If you are working on Android 2.2, you can remove it by the following step. Find StatusBarPolicy.java Find mBatteryIcon and add service.setIconVisibility(mBatteryIcon , false); for it. Remove all actions relevant to

Getting battery status from a service in Android

拟墨画扇 提交于 2019-12-06 17:32:25
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. 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 BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){ @Override public void onReceive(Context arg0,

Total Battery Capacity in mAh of device Programmatically

守給你的承諾、 提交于 2019-12-06 02:33:35
问题 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

Android BatteryManager Returns only 1

a 夏天 提交于 2019-12-06 01:40:15
I am attempting to read the state of the Android battery when my repeating alarm broadcaster is called I have the following setup: public class RepeatingAlarm extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Acquire the make of the device final String PhoneModel = android.os.Build.MODEL; final String AndroidVersion = android.os.Build.VERSION.RELEASE; // Grab the battery information int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); final float batteryPct = level / (float

How do Android and iOS scan for Bluetooth beacons without battery issues?

丶灬走出姿态 提交于 2019-12-05 18:37:04
if i want to develop own my iBeacon services in Android or IOS, it has to be practical. which means customer can use my services without shortage of battery. i think even if iBeacon technology is based on Bluetooth Low Energy, it could be still lack of battery. that's because an application must be running to scan iBeacon device all the time. As i know, iOS has its own solution for battery issue. when an IOS application detect iBeacon devices, it is running in the background and IOS(not app) is scanning specific UUIDs by itself, not the all UUIDs nearby. this is how they save energy. am i

How to find the battery recharge time of android mobile programatically?

巧了我就是萌 提交于 2019-12-05 16:51:23
I wanted to know that how can we find how much time android device will take to fully charge its battery. For example if my battery is 0% charged then how long it will take to charge full i.e. 100%, same if my device is 70% charge so if i connect charger now then how long it will take to full charge my device. You should read the official documentation about this. Basically you'll need to use BatteryManager class to find out current state of battery level. This worked for me: private void batteryLevel() { BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() { public void onReceive

iPhone running periodical process in the background - battery optimized way

隐身守侯 提交于 2019-12-05 13:28:18
I want to run a specific task in the background. This task takes few seconds to complete (it writes some GPS location data to a file). This task should run once every 1 hour. As I understand from the SDK, I do not have a way to INITIATE something in the background unless I run Location Services forever. When this service runs, it gives me an event from time to time, and I'm able to run my code during these calls. I tried it, and even with the minimal precision possible, my battery goes down very quickly. So, I'm looking for a way to run Location Services for few seconds every hour. All the