Je cherche une action pour IntentFilter qui est fournie lorsque le statut GPS est modifié. J'ai trouvé ceci filter.addAction("android.location.GPS_ENABLED_CHANGE");
mais cela ne fonctionne pas. Je regarde la même chose que j'ai pour bluetooth
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
mais pour le GPS.Action pour le changement de statut GPS
1
A
Répondre
2
Voici un exemple.
public class Main extends Activity implements LocationListener {
/* this class implements LocationListener, which listens for both
* changes in the location of the device and changes in the status
* of the GPS system.
* */
static final String tag = "Main"; // for Log
LocationManager lm;
StringBuilder sb;
int noOfFixes = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* the location manager is the most vital part it allows access
* to location and GPS status services */
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
}
@Override
protected void onResume() {
/*
* onResume is is always called after onStart, even if the app hasn't been
* paused
*
* add location listener and request updates every 1000ms or 10m
*/
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10f, this);
super.onResume();
}
@Override
protected void onPause() {
/* GPS, as it turns out, consumes battery like crazy */
lm.removeUpdates(this);
super.onPause();
}
@Override
public void onLocationChanged(Location location) {
Log.v(tag, "Location Changed");
sb = new StringBuilder(512);
noOfFixes++;
/* display some of the data in the TextView */
sb.append("No. of Fixes: ");
sb.append(noOfFixes);
sb.append('\n');
sb.append('\n');
sb.append("Londitude: ");
sb.append(location.getLongitude());
sb.append('\n');
sb.append("Latitude: ");
sb.append(location.getLatitude());
sb.append('\n');
sb.append("Altitiude: ");
sb.append(location.getAltitude());
sb.append('\n');
sb.append("Accuracy: ");
sb.append(location.getAccuracy());
sb.append('\n');
sb.append("Timestamp: ");
sb.append(location.getTime());
sb.append('\n');
Log.v(tag, sb.toString());
}
@Override
public void onProviderDisabled(String provider) {
/* this is called if/when the GPS is disabled in settings */
Log.v(tag, "Disabled");
/* bring up the GPS settings */
Intent intent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
@Override
public void onProviderEnabled(String provider) {
Log.v(tag, "Enabled");
Toast.makeText(this, "GPS Enabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
/* This is called when the GPS status alters */
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
Log.v(tag, "Status Changed: Out of Service");
Toast.makeText(this, "Status Changed: Out of Service",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Log.v(tag, "Status Changed: Temporarily Unavailable");
Toast.makeText(this, "Status Changed: Temporarily Unavailable",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.AVAILABLE:
Log.v(tag, "Status Changed: Available");
Toast.makeText(this, "Status Changed: Available",
Toast.LENGTH_SHORT).show();
break;
}
}
@Override
protected void onStop() {
/* may as well just finish since saving the state is not important for this toy app */
finish();
super.onStop();
}
}
-1
essayez ceci:
filter.addAction("android.location.PROVIDERS_CHANGED")
Questions connexes
- 1. Android écouter le changement de statut GPS?
- 2. Écoute du changement de statut GPS
- 3. Comment tester le statut GPS?
- 4. test GPS sans changement de position?
- 5. Requête Jira pour le changement de statut dans une heure
- 6. règles de changement de statut de test
- 7. Obtenir le statut GPS sur l'emplacement a changé
- 8. facebook relation statut changement commentaires
- 9. workflow 4.0 changement de statut de persistance
- 10. Notification de changement de position GPS
- 11. jquery changement form action
- 12. Wordpress Changement de statut de commentaire hook
- 13. Changement de fournisseur réseau et GPS
- 14. Meteor/React: changement d'état basé sur le statut de connexion
- 15. Service Android pour effectuer une action sur le changement d'emplacement
- 16. changement URl Après action Get
- 17. Action de déclenchement sur le changement de ticket Trac?
- 18. Interaction action actuelle et l'activité de changement
- 19. Comment recevoir les gps activés/désactivés?
- 20. variable = windows.open() action sur le changement d'entrée de formulaire
- 21. Exécution d'une action sur le changement de focus
- 22. firefox: pourquoi pas de changement dans ma barre de statut?
- 23. Android GPS: spécifiez NTP_SERVER pour GPS dans le code
- 24. Détection du changement de statut dans une série temporelle
- 25. changement action bouton pour url script adresse ou bash
- 26. changement C# cible action/délégué: appels hiérarchiques
- 27. GPS Android juste le premier changement de lieu entraîne onLocationChanged, pourquoi?
- 28. Comment éviter le problème Statut GPS -Temporairement indisponible dans mon application android
- 29. commence gps Android lorsque le GPS fixes
- 30. Activer le GPS comme le GPS activer/désactiver le widget