我发送一个字符串额外的麻烦PendingIntent,我传递给我LocationServices.FusedLocationApi.requestLocationUpdates(GoogleApiClient client, LocationRequest request, PendingIntent callbackIntent).
看来,我正在加入的用户名Intent正在破坏requestLocationUpdates试图交给我IntentService作为intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED)回报的位置null.
编辑
我已经尝试创建一个User实现Parcelable并将其作为额外的类:
mRequestLocationUpdatesIntent.putExtra("username", new User(username));
Run Code Online (Sandbox Code Playgroud)
我还尝试通过此错误报告https://code.google.com/p/android/issues/detail?id=81812中的评论建议将Parcelable User内部设置Bundle为内置:
Bundle userBundle = new Bundle();
userBundle.putParcelable("user", new User(username));
mRequestLocationUpdatesIntent.putExtra("user", userBundle);
Run Code Online (Sandbox Code Playgroud)
在我的服务中:
Bundle userBundle = intent.getBundleExtra("user");
User user = userBundle.getParcelable("user");
String username = user.getUsername();
Run Code Online (Sandbox Code Playgroud)
然而,这些方法都没有任何区别.每当我对我的意图添加任何额外内容时,在更新发生时,该位置永远不会添加到意图中.
我设置此IntentService处理位置更新:
public class LocationUpdateService extends IntentService {
private final String TAG = "LocationUpdateService";
public LocationUpdateService() { …Run Code Online (Sandbox Code Playgroud) android android-intent android-location google-play-services fusedlocationproviderapi
android ×1