Prevent crash on doze settings

Refs #302
This commit is contained in:
M66B 2016-03-24 10:11:24 +01:00
parent 826df8c014
commit 1adbc3c051
1 changed files with 4 additions and 2 deletions

View File

@ -636,8 +636,10 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
private void checkDoze() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final Intent doze = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (!pm.isIgnoringBatteryOptimizations(getPackageName())) {
if (!pm.isIgnoringBatteryOptimizations(getPackageName()) &&
getPackageManager().resolveActivity(doze, 0) != null) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!prefs.getBoolean("nodoze", false)) {
LayoutInflater inflater = LayoutInflater.from(this);
@ -650,7 +652,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
@Override
public void onClick(DialogInterface dialog, int which) {
prefs.edit().putBoolean("nodoze", cbDontAsk.isChecked()).apply();
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
startActivity(doze);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {