use of android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS in project android by nextcloud.
the class SyncedFoldersActivity method showBatteryOptimizationInfo.
private void showBatteryOptimizationInfo() {
if (powerManagementService.isPowerSavingExclusionAvailable() || checkIfBatteryOptimizationEnabled()) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.Theme_ownCloud_Dialog).setTitle(getString(R.string.battery_optimization_title)).setMessage(getString(R.string.battery_optimization_message)).setPositiveButton(getString(R.string.battery_optimization_disable), (dialog, which) -> {
// show instant upload
@SuppressLint("BatteryLife") Intent intent = new Intent(ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + BuildConfig.APPLICATION_ID));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}).setNeutralButton(getString(R.string.battery_optimization_close), (dialog, which) -> dialog.dismiss()).setIcon(R.drawable.ic_battery_alert);
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
AlertDialog alertDialog = alertDialogBuilder.show();
ThemeButtonUtils.themeBorderlessButton(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE), alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
}
}
}
Aggregations