【发布时间】:2015-07-09 18:10:11
【问题描述】:
我正在使用 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()));
}
}
}
【问题讨论】:
-
这很有趣,根本没有记录。我一直只使用一个监听器,所以我还没有看到 PendingIntents 的样子。你能显示你的代码吗?我想测试一下。
-
没有记录,但似乎为 developer.android.com/reference/com/google/android/gms/location/… 调用了 PendingIntent
-
类名的 LogCat 输出是什么?
标签: android android-fusedlocation android-googleapiclient