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

时间:2018-11-23 12:32:57

标签: android broadcastreceiver

我正在尝试实现一种接收器,该接收器对连接或断开的蓝牙设备做出反应。但是,只有在应用程序打开时,我才会收到广播。

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

state.js

我的接收器看起来像这样:

getters.js

打开应用程序时,此方法很好用,但是如果我打开。使用任务切换器并滑动活动,就不再接收广播。

<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());
    }
}

我还检查了implicit broadcast exceptions,并在其中列出了这两个动作。

1 个答案:

答案 0 :(得分:0)

尝试

<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> 
相关问题