【发布时间】:2015-08-12 07:59:43
【问题描述】:
我通过PendingIntent 请求一系列位置更新,并设置BroadcastReceiver 来处理位置更新。这是一个示例PendingIntent:
Intent locationIntent = new Intent(context, LocationReceiver.class);
locationIntent.putExtra("foo", "bar");
pendingIntent = PendingIntent.getBroadcast(context, 0, locationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
这是请求位置更新的代码:
final LocationRequest request = LocationRequest.create();
request.setInterval(UPDATE_INTERVAL);
request.setExpirationDuration(WAKEUP_DELTA * 2);
request.setNumUpdates(NUM_UPDATES);
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setLocationServices.FusedLocationApi.requestLocationUpdates(locationClient, request, pendingIntent);
问题是这样的:似乎如果我在意图中包含任何额外内容,则位置不会被包含在内。也就是说,当我调用intent.getExtras().get(FusedLocationProviderApi.KEY_LOCATION_CHANGED); 时,结果为空。如果我不向我的Intent 添加额外内容,Location 会出现在额外内容中!
我尝试了各种解决方法,包括 Location Client request location updates with parcelable extras in PendingIntent 的各种迭代,但这似乎对我不起作用。有没有办法解决这个问题,而不是想出一些方法来将额外的存储在其他地方并在执行位置接收器时检索它们?还是我做错了什么?
【问题讨论】:
-
你能找到解决这个@Catherine 的方法吗?