本文整理汇总了Java中android.os.BatteryManager.getIntProperty方法的典型用法代码示例。如果您正苦于以下问题:Java BatteryManager.getIntProperty方法的具体用法?Java BatteryManager.getIntProperty怎么用?Java BatteryManager.getIntProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.BatteryManager
的用法示例。
在下文中一共展示了BatteryManager.getIntProperty方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBatteryAveragePower
import android.os.BatteryManager; //导入方法依赖的package包/类
/**
* Calculate Average Power
* Average Power = (Average Voltage * Average Current) / 1e9
*
* @param context Context of application
* @return Average power in integer
*/
public static int getBatteryAveragePower(final Context context) {
int voltage;
int current = 0;
Intent receiver =
context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (receiver == null) return -1;
voltage = receiver.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
BatteryManager manager = (BatteryManager)
context.getSystemService(Context.BATTERY_SERVICE);
current = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE);
}
return (voltage * current) / 1000000000;
}
示例2: draw
import android.os.BatteryManager; //导入方法依赖的package包/类
private void draw() {
SurfaceHolder holder = getSurfaceHolder();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
if (canvas != null) {
//set colors from preferences
Preferences.resolveMode(getBaseContext(), canvas, chargecolor, dischargecolor);
//get battery level
BatteryManager bm = (BatteryManager) getBaseContext().getSystemService(BATTERY_SERVICE);
int batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
if (Preferences.batteryText(getBaseContext()))
Preferences.drawText(getBaseContext(), paint, canvas, Integer.toString(batLevel), batterycolor, rect);
}
} finally {
if (canvas != null)
holder.unlockCanvasAndPost(canvas);
}
handler.removeCallbacks(drawRunner);
if (visible) {
handler.postDelayed(drawRunner, 100);
}
}
示例3: getBatteryPercent
import android.os.BatteryManager; //导入方法依赖的package包/类
public static String getBatteryPercent(Context context){
//获取电池电量
BatteryManager batteryManager=(BatteryManager)context.getSystemService(Context.BATTERY_SERVICE);
String battery= null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
battery = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)+"";
}
return battery;
}
示例4: getBatteryChargeCounter
import android.os.BatteryManager; //导入方法依赖的package包/类
public static int getBatteryChargeCounter(final Context context) {
if (Build.VERSION.SDK_INT >= 21) {
BatteryManager manager = (BatteryManager)
context.getSystemService(Context.BATTERY_SERVICE);
return manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER);
}
return -1;
}
示例5: getBatteryCurrentAverage
import android.os.BatteryManager; //导入方法依赖的package包/类
public static int getBatteryCurrentAverage(final Context context) {
int value = -1;
if (Build.VERSION.SDK_INT >= 21) {
BatteryManager manager = (BatteryManager)
context.getSystemService(Context.BATTERY_SERVICE);
value = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE);
}
return (value != Integer.MIN_VALUE) ? value : -1;
}
示例6: getBatteryCurrentNow
import android.os.BatteryManager; //导入方法依赖的package包/类
public static int getBatteryCurrentNow(final Context context) {
int value;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
BatteryManager manager = (BatteryManager)
context.getSystemService(Context.BATTERY_SERVICE);
value = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW);
} else {
value = getBatteryCurrentNowLegacy();
}
return (value != Integer.MIN_VALUE) ? -value / 1000 : -1;
}
示例7: getBatteryCapacityConsumed
import android.os.BatteryManager; //导入方法依赖的package包/类
/**
* Calculate Battery Capacity Consumed
* Battery Capacity Consumed = (Average Current * Workload Duration) / 1e3
*
* @param workload Workload duration (in hours)
* @param context Context of application
* @return Average power in integer
*/
public static double getBatteryCapacityConsumed(final double workload, final Context context) {
int current = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
BatteryManager manager = (BatteryManager)
context.getSystemService(Context.BATTERY_SERVICE);
current = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE);
}
return (current * workload) / 1000;
}
示例8: getBatteryLevel
import android.os.BatteryManager; //导入方法依赖的package包/类
public static int getBatteryLevel(Context context) {
BatteryManager bm = (BatteryManager)context.getSystemService(BATTERY_SERVICE);
return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
}
示例9: resolveMode
import android.os.BatteryManager; //导入方法依赖的package包/类
static void resolveMode(Context context, Canvas canvas, int charge, int discharge) {
float height;
float width;
WindowManager window = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//retrieve display specifications
DisplayMetrics d = new DisplayMetrics();
window.getDefaultDisplay().getRealMetrics(d);
width = d.widthPixels;
height = d.heightPixels;
Paint p = new Paint();
Paint p2 = new Paint();
//get battery level
BatteryManager bm = (BatteryManager) context.getSystemService(BATTERY_SERVICE);
float batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
//do some proportions
float battery_complementary = height - ((batLevel * height) / 100);
//Mode options
String choice = PreferenceManager.getDefaultSharedPreferences(context)
.getString(context.getString(R.string.pref_mode), String.valueOf(0));
switch (Integer.parseInt(choice)) {
default:
case 0:
//set colors
p.setColor(discharge);
p2.setColor(charge);
//draw rectangles according to display height and battery level
canvas.drawRect(0, 0, width, height, p2);
canvas.drawRect(0, 0, width, battery_complementary, p);
break;
case 1:
//draw rectangle according to battery-context
batteryModes(context, p, batLevel);
canvas.drawRect(0, 0, width, height, p);
break;
case 2:
//draw rectangles according to battery level and time-context
dayModes(context, p, p2);
canvas.drawRect(0, 0, width, height, p2);
canvas.drawRect(0, 0, width, battery_complementary, p);
break;
}
}