How to receive intents for Bluetooth devices working?

眉间皱痕 提交于 2019-12-06 02:48:17

I have a very similar code which works, the only major difference i found was this:

mLocalBroadcastManager.registerReceiver(mMessageReceiver, filter);

i beleive that registerReceiver should be called from the context you want to get intents to. try calling the method from this. i.e remove the mLocalBroadcastManager like:

registerReceiver(mMessageReceiver, filter);

If you Register the Receiver on the Manifest instead of the Activity, you can receive broadcasts even if you do not have the app opened, you can do this:

    <receiver android:name=".BluetoothReceiver" >
        <intent-filter>
            <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
            <action android:name="android.bluetooth.device.action.BOND_STATE_CHANGED" />
        </intent-filter>
    </receiver>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!