version:3.9
fix:修复系统设置管控失败 update:
This commit is contained in:
@@ -928,23 +928,7 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电量
|
||||
*
|
||||
* @param mContext
|
||||
* @return
|
||||
*/
|
||||
synchronized private static int getBatteryLevel(Context mContext) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
|
||||
} else {
|
||||
Intent intent = (new ContextWrapper(mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
|
||||
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* 更新应用白名单禁止升级
|
||||
*
|
||||
* @param context
|
||||
@@ -1269,6 +1253,7 @@ public class Utils {
|
||||
jsonObject.put("charging", charging);
|
||||
jsonObject.put("memory", memory);
|
||||
jsonObject.put("storage", storage);
|
||||
jsonObject.put("battery_capacity", Utils.getBatterymAh(context));
|
||||
jsonObject.put("CPU", CPU + "核");
|
||||
String jsonString = jsonObject.toJSONString();
|
||||
Log.e(TAG, "getHardware: " + jsonString);
|
||||
@@ -1312,6 +1297,36 @@ public class Utils {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double getBatterymAh(Context context) {
|
||||
Object mPowerProfile;
|
||||
double batteryCapacity = 0; //电池的容量mAh
|
||||
final String POWER_PROFILE_CLASS = "com.android.internal.os.PowerProfile";
|
||||
try {
|
||||
mPowerProfile = Class.forName(POWER_PROFILE_CLASS).getConstructor(Context.class).newInstance(context);
|
||||
batteryCapacity = (double) Class.forName(POWER_PROFILE_CLASS).getMethod("getBatteryCapacity").invoke(mPowerProfile);
|
||||
Log.e("getBattery", "battery mAh: " + batteryCapacity);
|
||||
} catch (Exception e) {
|
||||
Log.e("getBattery", "get batteryCapacity mAh error:" + batteryCapacity);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return batteryCapacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电量
|
||||
*
|
||||
* @param mContext
|
||||
* @return
|
||||
*/
|
||||
synchronized private static int getBatteryLevel(Context mContext) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
|
||||
} else {
|
||||
Intent intent = (new ContextWrapper(mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
|
||||
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getBatteryPercentage(Context context) {
|
||||
|
||||
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
|
||||
Reference in New Issue
Block a user