version:1.9
fix: add:接口缓存
This commit is contained in:
@@ -60,7 +60,6 @@ import com.uiui.sn.Statistics.AppInformation;
|
||||
import com.uiui.sn.Statistics.StatisticsInfo;
|
||||
import com.uiui.sn.bean.AppUsed;
|
||||
import com.uiui.sn.config.CommonConfig;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -1008,6 +1007,20 @@ public class Utils {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void 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();
|
||||
}
|
||||
}
|
||||
|
||||
synchronized private static int getBatteryLevel(Context mContext) {
|
||||
if (Build.VERSION.SDK_INT >= 21)
|
||||
return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
|
||||
@@ -1015,6 +1028,19 @@ public class Utils {
|
||||
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
|
||||
}
|
||||
|
||||
public static int getBatteryPercentage(Context context) {
|
||||
|
||||
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
Intent batteryStatus = context.registerReceiver(null, iFilter);
|
||||
|
||||
int level = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) : -1;
|
||||
int scale = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1) : -1;
|
||||
|
||||
float batteryPct = level / (float) scale;
|
||||
|
||||
return (int) (batteryPct * 100);
|
||||
}
|
||||
|
||||
public static int getIsCharging(Context context) {
|
||||
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
Intent batteryStatus = context.registerReceiver(null, ifilter);
|
||||
|
||||
Reference in New Issue
Block a user