Bonjour,
Je veux afficher une AlertDialog au lancement de mon application si le GPS est désactivé. Cette AlertDialog préviens l'utilisateur qu'il doit activer le GPS pour utiliser l'application, et s'il accepte, le renvoyer vers le menu des paramètres de localisation.
Le problème, c'est que cette AlertDialog ne s'affiche pas, j'ai un écran noir qui mouline, pourtant le code de ma fonction d'affichage est bien exécuté.
Voici mon code :
Savez-vous d'où le problème peut venir et comment le résoudre ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Hide the window title. requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); context = this; clickListener = new MarkerListener(); locationListener = new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } public void onLocationChanged(Location location) { // ... on sauvegarde la position myLoc = location; } } }; locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { System.out.println("GPS désactivé"); // S'affiche bien showDialog(GPS_DIALOG); } myLoc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 3, locationListener); while (myLoc == null) { // Wait for a not-null location } } @Override protected Dialog onCreateDialog(int id) { Dialog dialog; switch(id) { case GPS_DIALOG: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Le GPS doit être activé pour pouvoir utiliser ce module."); builder.setCancelable(false); builder.setPositiveButton("Activer le GPS", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { startActivity(new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }); builder.setNegativeButton("Quitter le module", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { dialog.cancel(); finish(); } }); dialog = builder.create(); break; default: dialog = null; } return dialog; }
Merci d'avance, cordialement,
Aenur56
Partager