kevinpato Posted February 8, 2010 Share Posted February 8, 2010 Dans le cadre d'un projet scolaire, je développe une appli sous android qui utilise le GPS, l'appli fonctionne bien mais uniquement si le GPS est activé. S'il est désactivé, l'appli plante. Comment est il possible de vérifier l'etat du GPS et dire à l'utilisateur d'activer celui-ci ? J'ai essayé avec GpsStatus.Listener mais ca ne fonctionne pas... Link to comment Share on other sites More sharing options...
kev.android Posted April 9, 2011 Share Posted April 9, 2011 heu, j'aimerais bien faire exactement la même chose, si quelqu'un a la solution. Merci d'avance Link to comment Share on other sites More sharing options...
nbatteur Posted April 13, 2011 Share Posted April 13, 2011 Il suffit sur l'objet locationManager de faire appel à la méthode isProviderEnabled(LocationManager.GPS_PROVIDER) qui renvoi un boolean ;) Si ce n'est pas actif, il faut ouvrir l'activité (avec un intent) android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS ca n'activera pas le gps mais ouvre la page de paramétrage permettant de l'activer. Bizarrement kevinpato, on a eu le même genre de projet scolaire au même moment ;) Link to comment Share on other sites More sharing options...
kev.android Posted April 27, 2011 Share Posted April 27, 2011 Merki bien pour la réponse. Sinon un autre bout de code juste pour la verif qui marche: private boolean isGPSActif(){ String allowedLocationProviders = Settings.System.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if (allowedLocationProviders == null) allowedLocationProviders = ""; return allowedLocationProviders.contains(LocationManager.GPS_PROVIDER); } Voilà ++ Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.