mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-11 04:25:53 +00:00
Dont crash if request ignore battery optimizations is not supported
This commit is contained in:
parent
4c8a98d169
commit
31721af0c3
2 changed files with 11 additions and 1 deletions
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -148,7 +149,15 @@ public class MainActivity extends SyncthingActivity
|
|||
.setPositiveButton(R.string.dialog_disable_battery_optimization_turn_off, (d, i) -> {
|
||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
||||
intent.setData(Uri.parse("package:" + getPackageName()));
|
||||
startActivity(intent);
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
// Some devices dont seem to support this request (according to Google Play
|
||||
// crash reports).
|
||||
Log.w(TAG, "Request ignore battery optimizations not supported", e);
|
||||
Toast.makeText(this, R.string.dialog_disable_battery_optimizations_not_supported, Toast.LENGTH_LONG).show();
|
||||
sp.edit().putBoolean("battery_optimization_dont_show_again", true).apply();
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.dialog_disable_battery_optimization_later, (d, i) -> mBatteryOptimizationDialogDismissed = true)
|
||||
.setNegativeButton(R.string.dialog_disable_battery_optimization_dont_show_again, (d, i) -> {
|
||||
|
|
|
@ -60,6 +60,7 @@ Please report any problems you encounter via Github.</string>
|
|||
<string name="dialog_disable_battery_optimization_later">Later</string>
|
||||
<string name="dialog_disable_battery_optimization_dont_show_again">Don\'t show again</string>
|
||||
<string name="dialog_disable_battery_optimization_turn_off">Turn off for Syncthing</string>
|
||||
<string name="dialog_disable_battery_optimizations_not_supported">Your device does not support disabling battery optimizations</string>
|
||||
|
||||
<!-- FoldersFragment -->
|
||||
|
||||
|
|
Loading…
Reference in a new issue