【发布时间】:2016-07-29 07:42:28
【问题描述】:
我在接收位置更新时触发了一个 BoradcastReceiver
PendingIntent pendingIntent = PendingIntent
.getBroadcast(this, 54321, intent, PendingIntent.FLAG_CANCEL_CURRENT);
LocationServices.FusedLocationApi.requestLocationUpdates(this.mGoogleApiClient,
mLocationRequest, pendingIntent);
还有我的接收器
public static class LocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
boolean hasLocation = LocationResult.hasResult(intent);
}
}
如果我运行上面的代码,一切正常,hasLocation 总是正确的,完美的。
但如果我想将一些变量传递给接收器,我会这样做:
Intent intent = ..
intent.putExtra("test", "hello");
PendingIntent pendingIntent = PendingIntent
.getBroadcast(this, 54321, intent, PendingIntent.FLAG_CANCEL_CURRENT);
现在位在接收方 LocationResult.hasResult(intent);总是假的
这是一个错误吗?有解决方法吗?如何将变量传递给接收方?
【问题讨论】:
-
hasResult是返回真还是假? -
当我没有在 Intent 中添加任何额外内容时,hasResult 返回 TRUE
-
你说 hasResult 总是 NULL,但它返回一个布尔值。是真的还是假的?如果您确实在意图中添加了额外内容
-
很抱歉给您带来了困惑。我的意思总是错误的。
-
如果你记录额外的意图,你会得到什么?
标签: android android-intent service location broadcastreceiver