This commit is contained in:
2021-12-03 17:46:59 +08:00
commit 6c2eb5a1a3
287 changed files with 3854 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package com.uiui.os.utils;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Build;
public class Utils {
/**
* 获取电量
*
* @param mContext
* @return
*/
synchronized public 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);
}
}
}