battery

Getting iPhone's battery level

旧城冷巷雨未停 提交于 2019-11-27 20:36:40
问题 I have a simple question. How do I get iPhone's battery level? [UIDevice currentDevice] batteryLevel] Simple enough? However there is a little catch - I can't use UIKit . Here is what I wrote so far, but I don't think it works: // notification port IONotificationPortRef nport = IONotificationPortCreate(kIOMasterPortDefault); CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(nport), kCFRunLoopDefaultMode); CFMutableDictionaryRef matching = IOServiceMatching(

Fetch the battery status of my MacBook with Swift

廉价感情. 提交于 2019-11-27 18:48:12
问题 I want to setup a Playground to fetch the battery status of my macbook. I have already tried the following: import Cocoa import IOKit import Foundation var blob = IOPSCopyPowerSourcesInfo() I am currently receiving an error as below Use of unresolved identifier 'IOPSCopyPowerSourcesInfo' 回答1: It doesn't work in a Playground, but it works in a real app. I couldn't access the IOPowerSources.h header file with Swift and import IOKit only, though: I had to make a bridge to Objective-C. Here's my

Is my Android App Draining Battery?

家住魔仙堡 提交于 2019-11-27 17:04:35
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 (scientifically) if I've made any improvements. Unfortunately, I don't have any prior data to go by, so

Android data storage - File vs SQLite

感情迁移 提交于 2019-11-27 16:17:01
问题 I am developing an application that periodically sends information to an external server. I make a local copy of the data being sent, for backup purposes. What is the best option to store the data in terms of saving battery life ? Each data submission is a serialized object (the class has 5 fields, including a date, numbers and strings) of about 5K-10K. Any other idea? 回答1: I have no idea in terms of battery life directly but one criteria would be which is easier to manage? Fewer operations

ACTION_BATTERY_CHANGED firing like crazy

女生的网名这么多〃 提交于 2019-11-27 13:43:58
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_BATTERY_CHANGED)); for (int i = 0; i < N; i++) { int appWidgetId = appWidgetIds[i]; appWidgetManager

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

天大地大妈咪最大 提交于 2019-11-27 11:51:17
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 = mBluetoothGatt.getService(Battery_Service_UUID); if(batteryService == null) { Log.d(TAG, "Battery

Battery-safe coding

江枫思渺然 提交于 2019-11-27 09:48:10
I was wondering if there are some rules or hints how to prevent battery drain directly while coding. I know that there may be some ways to code to minimize workload on the processor or prevent leaks. However, does anybody have something like a guide or a something like a "checklist" besides the usual suspects like location service and internet connection? I'll assume you mean your application. In my experience, the major consumers of energy are, where #1 is most important: CPU usage 4G WiFi Bluetooth Memory Whether 4G or WiFi is worse depends upon your usage, e.g. whether you are talking with

Android : Is there anyway to get battery capacity of a device in mah?

扶醉桌前 提交于 2019-11-27 09:08:49
I want to get battery capacity of a device to do some battery consumption computation, is it possible to get it somehow? For instance, battery capacity for Samsung Galaxy Note 2 is 3100 mah. Thanks for helping. Got it! Couldn't find anything straight in SDK but can be done using reflection. Here is the working code :- public void getBatteryCapacity() { Object mPowerProfile_ = null; 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) { e

Detecting the device being plugged in

て烟熏妆下的殇ゞ 提交于 2019-11-27 08:46:37
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? 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() { BroadcastReceiver receiver = new BroadcastReceiver() { public void onReceive(Context context, Intent

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

南笙酒味 提交于 2019-11-27 00:08:39
问题 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 is a better solution in terms of saving the user's battery. a) Opening and Closing the connection every time a command is sent, if the chat tab is opened then keep the connection constant. b) Keep the connection constant all the time. I've taken a