【问题标题】:Is sendBroadcast() required for a PendingIntent with an Intent for a broadcast receiver?带有广播接收器意图的 PendingIntent 是否需要 sendBroadcast()?
【发布时间】:2017-01-25 13:06:28
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: android broadcastreceiver android-pendingintent location-services


    【解决方案1】:

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

    不,你不必这样做。

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

    检索将执行广播的 PendingIntent,就像调用 Context.sendBroadcast()


    或者,将带有 Intent 的 PendingIntent 用于 BroadcastReceiver 是否足以让结果到达他们需要的地方?

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

    【讨论】:

      猜你喜欢
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多