Update DisableBattery.java
This commit is contained in:
@@ -19,24 +19,17 @@ import ru.vtosters.lite.deviceinfo.OEMDetector;
|
||||
|
||||
public class DisableBattery {
|
||||
public static void alert(Activity activity) {
|
||||
if (OEMDetector.isOEM() && Build.VERSION.SDK_INT >= 23 && getBoolValue("showDoze", true)) {
|
||||
final Context context = getGlobalContext();
|
||||
if (!((PowerManager) context.getSystemService(Context.POWER_SERVICE)).isIgnoringBatteryOptimizations(context.getPackageName())) {
|
||||
new VkAlertDialog.Builder(activity)
|
||||
.setTitle(getString("batteryissuetitle"))
|
||||
.setMessage(getString("batteryissuesumm"))
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(getString("batteryissuebtn1"), (dialogInterface, i) -> {
|
||||
var intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.setData(Uri.parse("package:" + context.getPackageName()));
|
||||
context.startActivity(intent);
|
||||
})
|
||||
.setNeutralButton(getString("batteryissuebtn2"),
|
||||
(dialogInterface, i) -> edit().putBoolean("showDoze", false).apply()
|
||||
)
|
||||
.show();
|
||||
if (OEMDetector.isOEM() && Build.VERSION.SDK_INT >= 23) {
|
||||
Intent intent = new Intent();
|
||||
String packageName = activity.getPackageName();
|
||||
PowerManager pm = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
|
||||
if (pm.isIgnoringBatteryOptimizations(packageName))
|
||||
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
||||
else {
|
||||
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
||||
intent.setData(Uri.parse("package:" + packageName));
|
||||
}
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user