具有广播接收器 Intent 的 PendingIntent 是否需要 sendBroadcast()?

Is sendBroadcast() required for a PendingIntent with an Intent for a broadcast receiver?

我的应用程序需要定期更新用户的位置,以便在 GoogleMap 上显示它们。

为了实现这一点,我使用了 LocationServices.FusedLocationApi.requestLocationUpdates() 方法,结果被发送到指定的 PendingIntent .

PendingIntentIntent 是一个 BroadcastReceiver,其 onReceive() 方法将处理结果。

我的问题是:我是否需要在某处调用 sendBroadcast() 以便广播接收器接收结果,如果需要,在哪里?

或者,将带有 IntentPendingIntent 发送到 BroadcastReceiver 是否足够让结果到达他们需要的地方?

Do I need to invoke sendBroadcast() somewhere in order for the results to be received by the broadcast receiver, and if so, where?

不,你不必那样做。

如果您查看 PendingIntent.getBroadcast() 的 javadoc,您会看到

Retrieve a PendingIntent that will perform a broadcast, like calling Context.sendBroadcast().


Or, is it sufficient to have the PendingIntent with an Intent to a BroadcastReceiver for the results to get where they need to?

是的,这就足够了,但请注意,您需要使用 PendingIntent.getBroadcast()