Я использую com.google.android.gms: play-services: 7.3.0. Этого не произошло с 6.5.Почему Android FusedLocationProviderApi requestLocationUpdates отправляет обновления с помощью странных ключей?
The documentation говорит: Обновления
местоположений отправляются с ключом KEY_LOCATION_CHANGED и значением Места на умысле.
Ну, это правда. Он также отправляет обновления с ключом: com.google.android.gms.location.EXTRA_LOCATION_RESULT
и еще одно обновление с ключом: com.google.android.gms.location.EXTRA_LOCATION_AVAILABILITY
Что это за? Где они задокументированы?
Вот мой код:
// Needed for all API calls
mClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mClient.connect();
// Create the LocationRequest object
mLocationRequest = LocationRequest.create();
// Use high accuracy
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// Set the update interval to 5 seconds
mLocationRequest.setInterval(5000);
// Set the fastest update interval
mLocationRequest.setFastestInterval(5000);
Intent locationIntent = new Intent(this, LocationReceiver.class);
@Override
public void onConnected(Bundle connectionHint) {
Intent locationIntent = new Intent(this, LocationReceiver.class);
// Set up periodic location updates
mLocationPendingIntent = PendingIntent.getBroadcast(this, 0, locationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mFusedLocationProviderApi.requestLocationUpdates(mClient, mLocationRequest, mLocationPendingIntent);
}
И тогда это мой LocationReceiver:
public class LocationReceiver extends BroadcastReceiver {
private static final String TAG = "LocationReceiver";
@Override
public void onReceive(Context context, Intent intent) {
android.os.Debug.waitForDebugger(); // this line is key
Log.w(TAG, "received location!");
Bundle extras = intent.getExtras();
// Log intent details
for (String key : extras.keySet()) {
Object value = extras.get(key);
Log.d(TAG, String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
}
}
Это интересно, это не документировано вообще. Я всегда использовал слушателя, поэтому я не видел, как выглядят PendingIntents. Можете ли вы показать свой код? Я бы хотел проверить это. –
Несомненно! Добавлен. –
Это не задокументировано, но кажется, что PendingIntent вызывается для https://developer.android.com/reference/com/google/android/gms/location/LocationAvailability.html – Kazuki