【问题标题】:Sending and receiving broadcast from the same receiver从同一个接收器发送和接收广播
【发布时间】:2013-12-28 07:15:49
【问题描述】:

您好,我正在尝试为我的地理围栏应用程序实现自定义广播接收器。我刚刚完成了解决方案given here 但我发现他正在从接收相同广播的接收器类发送广播。有人可以告诉我这是如何工作的。我在自定义广播方面工作不多。

【问题讨论】:

    标签: android broadcastreceiver android-broadcast android-geofence


    【解决方案1】:

    他正在从一个类发送广播并在另一个接收器中接收它。下面的行是他发送广播的地方。

                  Intent intent = new Intent("com.aol.android.geofence.ACTION_RECEIVE_GEOFENCE");
    

    这是他为该广播注册接收器的清单

       <receiver android:name="com.aol.android.geofence.GeofenceReceiver"
        android:exported="false">
        <intent-filter >
            <action android:name="com.aol.android.geofence.ACTION_RECEIVE_GEOFENCE"/>
        </intent-filter>
    </receiver>
    

    【讨论】:

    • 感谢您的回答。你能告诉我这条线是什么意思吗? broadcastIntent .setAction(GeofenceUtils.ACTION_GEOFENCE_TRANSITION) .addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES) .putExtra(GeofenceUtils.EXTRA_GEOFENCE_ID, geofenceIds) .putExtra(GeofenceUtils.EXTRA_GEOFENCE_TRANSITION_TYPE, transitionType); LocalBroadcastManager.getInstance(MyApplication.getContext()) .sendBroadcast(broadcastIntent);在接收器类中。这条线让我很困惑
    【解决方案2】:

    您可以使用以下代码在另一个广播中发送一个广播:

    ntent local = new Intent();
    local.setAction("BroadCastPath"); // like android.receiver.MyReceiver 
    context.sendBroadcast(local);
    

    【讨论】:

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