代码之家  ›  专栏  ›  技术社区  ›  manabreak

系统广播未发送到广播接收器

  •  0
  • manabreak  · 技术社区  · 7 年前

    我正在尝试实现一个接收器,它可以对蓝牙设备的连接或断开做出反应。然而,我只在申请打开时收到胸针。

    我已将接收者添加到舱单中:

    <receiver android:name=".BleReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
            <action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
        </intent-filter>
    </receiver>
    

    我的接收器是这样的:

    public class BleReceiver extends BroadcastReceiver {
        private static final String TAG = "BleReceiver";
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "Got intent: " + intent.getAction());
        }
    }
    

    当应用程序打开时,这一切正常,但如果我使用任务切换程序并滑动活动,则不会再收到广播。

    输出 adb shell cmd package query-receivers --brief -a android.bluetooth.device.action.ACL_CONNECTED 看起来很好:

    Receiver #3:
      priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
      com.example.blelistenerapp/.service.ble.BleReceiver
    

    此外,我还查看了 implicit broadcast exceptions ,下面列出了这两个操作。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Prasanth S    7 年前

    尝试

    <receiver android:name=".BleReceiver">
                <intent-filter>
                    <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
                    <action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
                    <action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
                </intent-filter>
            </receiver>