DialogAlert
This commit is contained in:
@@ -2,10 +2,12 @@ package fr.svpro.radiomercure;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -54,14 +56,33 @@ public class MainActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
//Réglage de l'app battery non optimisée par l'utilisateur
|
||||
//Demande d'autorisation de désactiver l'optimisation de la batterie
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(R.string.dialog_battery_msg)
|
||||
.setTitle(R.string.dialog_battery_titre);
|
||||
|
||||
builder.setPositiveButton(R.string.dialog_button_oui, (dialog12, id) -> {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
||||
//intent.setData(Uri.parse("package:"+ getApplicationInfo().packageName));
|
||||
startActivity(intent);
|
||||
|
||||
});
|
||||
builder.setNegativeButton(R.string.dialog_button_non, (dialog1, id) -> {
|
||||
// User cancelled the dialog
|
||||
Toast.makeText(this, "Annulation par l'utilisateur", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
AlertDialog alertDialog = builder.create();
|
||||
|
||||
|
||||
|
||||
|
||||
PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
Intent intent = new Intent();
|
||||
|
||||
if (!powerManager.isIgnoringBatteryOptimizations(getApplication().getPackageName())) {
|
||||
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
||||
//intent.setData(Uri.parse("package:"+ getApplicationInfo().packageName));
|
||||
startActivity(intent);
|
||||
alertDialog.show();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +200,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
return true;
|
||||
|
||||
case R.id.about:
|
||||
|
||||
dialog.show();
|
||||
return true;
|
||||
|
||||
@@ -245,6 +267,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
} else {
|
||||
onDestroy();
|
||||
reStart();
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user