本文整理匯總了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;
}
}