List of usage examples for android.os BatteryManager EXTRA_SCALE
String EXTRA_SCALE
To view the source code for android.os BatteryManager EXTRA_SCALE.
Click Source Link
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java
private void saveImageForDiagnostics(@NonNull byte[] data, String result) { IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = registerReceiver(null, intentFilter); int batteryPercent = -1; if (batteryStatus != null) { int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); batteryPercent = (int) ((level / (float) scale) * 100); }/*from ww w. j ava 2 s. co m*/ if (mIsCalibration) { result = String.format(Locale.US, "%.2f", mSwatchValue); } String date = new SimpleDateFormat("yyyy-MM-dd_HH-mm", Locale.US).format(new Date()); ImageUtil.saveImage(data, CaddisflyApp.getApp().getCurrentTestInfo().getId(), String.format(Locale.US, "%s_%s_%s_%d_%s", date, (mIsCalibration ? "C" : "T"), result, batteryPercent, ApiUtil.getInstallationId(this))); }
From source file:org.metawatch.manager.Monitors.java
private static void createBatteryLevelReciever(Context context) { if (batteryLevelReceiver != null) return;/*from w w w . ja v a2 s.c o m*/ batteryLevelReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); int level = -1; if (rawlevel >= 0 && scale > 0) { level = (rawlevel * 100) / scale; } boolean charging = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0; if (BatteryData.level != level || BatteryData.charging != charging) { //if (Preferences.logging) Log.d(MetaWatch.TAG, "Battery level changed: "+rawlevel+"/"+scale+" - "+level+"%"); BatteryData.level = level; BatteryData.charging = charging; Idle.updateIdle(context, true); } } }; context.registerReceiver(batteryLevelReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); }
From source file:com.dsna.android.main.MainActivity.java
public void logBatteryLevelAndProcessTime(long processedTime) { IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); batteryStatus = getApplicationContext().registerReceiver(null, ifilter); int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); float batteryPct = level / (float) scale; batteryPct = Math.max(Math.min(batteryPct, 1), 0); logBatteryAndProcessResult.append(System.currentTimeMillis()); logBatteryAndProcessResult.append(','); logBatteryAndProcessResult.append(batteryPct); logBatteryAndProcessResult.append(','); logBatteryAndProcessResult.append(processedTime); logBatteryAndProcessResult.append('\n'); }
From source file:org.pixmob.freemobile.netstat.MonitorService.java
private int getBatteryLevel() { if (batteryIntentFilter == null) { return 100; }//from w ww. j a v a2 s . co m final Intent i = registerReceiver(null, batteryIntentFilter); if (i == null) { return 100; } final int level = i.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); final int scale = i.getIntExtra(BatteryManager.EXTRA_SCALE, 0); return scale == 0 ? 100 : (int) Math.round(level * 100d / scale); }
From source file:com.droid.app.fotobot.FotoBot.java
/** * ? ?. ? , battery_level./*www.ja v a 2s . c o m*/ */ public void batteryLevel() { BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { //context.unregisterReceiver(this); int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); battery_temperature = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1)) / 10.0f; battery_level = -1; if (rawlevel >= 0 && scale > 0) { battery_level = (rawlevel * 100) / scale; } // int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); // isPlugged = plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB; // if (VERSION.SDK_INT > VERSION_CODES.JELLY_BEAN) { // isPlugged = isPlugged || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; // } } }; IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); registerReceiver(batteryLevelReceiver, batteryLevelFilter); }
From source file:org.mariotaku.twidere.util.Utils.java
public static boolean isBatteryOkay(final Context context) { if (context == null) return false; final Context app = context.getApplicationContext(); final IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); final Intent intent = app.registerReceiver(null, filter); if (intent == null) return false; final boolean plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0; final float level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); final float scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100); return plugged || level / scale > 0.15f; }
From source file:de.vanita5.twittnuker.util.Utils.java
public static boolean isBatteryOkay(final Context context) { if (context == null) return false; final Context app = context.getApplicationContext(); final IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); final Intent intent = app.registerReceiver(null, filter); if (intent == null) return false; final boolean plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0; final float level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); final float scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100); return plugged || level / scale > 0.15f; }