2

我正在使用 com.google.android.gms:play-services:7.3.0。这在 6.5 中没有发生。

文档说:

位置更新使用 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()));
        }
    }
}
4

1 回答 1

0

LocationAvailability 提供“位置数据可用性的状态”。

谷歌文档说:“从通过 #requestLocationUpdates(GoogleApiClient,LocationRequest,LocationCallback,Looper) 注册的 LocationCallback 或通过 #requestLocationUpdates(GoogleApiClient, LocationRequest, PendingIntent) 注册的 PendingIntent提供。它也可以通过 getLocationAvailability(GoogleApiClient) 按需提供。”

这就是您收到位置可用性数据的原因。

于 2015-07-02T06:53:05.583 回答