【问题标题】:Location Client request location updates with parcelable extras in PendingIntent位置客户端在 PendingIntent 中使用可打包的附加请求请求位置更新
【发布时间】:2015-02-02 20:46:39
【问题描述】:

我正在使用带有 PendingIntent 的 LocationClient 来获取位置更新。

PendingIntent.getService(context, 0, new Intent(context, OnLocationAvail.class), PendingIntent.FLAG_UPDATE_CURRENT)

上面的代码工作正常,我从键 LocationClient.KEY_LOCATION_CHANGED 获取位置

但是,当我有如下所述的额外可打包数据时,服务会使用可打包数据调用,但意图额外数据中的关键 LocationClient.KEY_LOCATION_CHANGED 始终为空。

Intent callbackIntent = new Intent(context, OnLocationAvail.class);
callbackIntent.putExtra(SOME_KEY, PARCELABLE_DATA);
PendingIntent.getService(context, 0, callbackIntent, PendingIntent.FLAG_UPDATE_CURRENT);

【问题讨论】:

  • 在哪里可以找到解决方案?

标签: android android-intent android-location


【解决方案1】:

问题是当 LocationClient 通过回调 PendingIntent 推送更新时,该进程没有 ClassLoader 的任何信息,因为它发生在应用程序上下文之外并且在不同的进程中。

以下链接帮助我缩小了问题范围。 https://code.google.com/p/android/issues/detail?id=6822

解决方案:

在请求位置更新时使用破解包。

Bundle bundle = new Bundle();
bundle.putParcelable("com.foo.parcel", some_parcel);
callbackPendingIntent.putExtra("com.foo.bundle",bundle);

收到位置更新时。

Bundle oldBundle = intent.getBundleExtra("com.foo.bundle");      
some_parcel = oldBundle.getParcelable("com.foo.parcel");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-03
    • 2016-06-25
    • 1970-01-01
    • 2012-03-06
    • 2015-12-07
    • 1970-01-01
    相关资源
    最近更新 更多