Here you can find the source of getBatteryUsageInfo(Context context)
Parameter | Description |
---|---|
context | the context of application |
public static String getBatteryUsageInfo(Context context)
//package com.java2s; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; public class Main { /**//from w w w . j ava 2 s . co m * Gets the battery info of device, and then writes it to a file. * * @param context the context of application */ public static String getBatteryUsageInfo(Context context) { Intent batteryIntent = context.getApplicationContext() .registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int rawlevel = batteryIntent.getIntExtra("level", -1); double scale = batteryIntent.getIntExtra("scale", -1); return String.format("Device has %s of %s battery left", rawlevel, scale); } }