Fix API level compatibility
Этот коммит содержится в:
@@ -116,11 +116,16 @@ public class TraccarService extends Service {
|
|||||||
wakeLock.release();
|
wakeLock.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.ECLAIR)
|
||||||
public double getBatteryLevel() {
|
public double getBatteryLevel() {
|
||||||
Intent batteryIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR) {
|
||||||
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
Intent batteryIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, 1);
|
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
||||||
return (level * 100.0) / scale;
|
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, 1);
|
||||||
|
return (level * 100.0) / scale;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PositionProvider.PositionListener positionListener = new PositionProvider.PositionListener() {
|
private PositionProvider.PositionListener positionListener = new PositionProvider.PositionListener() {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user