关于蓝牙开发,必须注意的广播

/**有注释的广播,蓝牙连接时都会用到

* bind一般会停止搜索ACTION_DISCOVERY_FINISHED

* @param cxt

*/

intentFilter.addAction(BluetoothDevice.ACTION_FOUND); //搜索蓝压设备,每搜到一个设备发送一条广播

intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); //配对开始时,配对成功时

intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); //配对时,发起连接

intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);

intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); //配对结束时,断开连接

intentFilter.addAction(PAIRING_REQUEST); //配对请求

(android.bluetooth.device.action.PAIRING_REQUEST)

intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);//开始搜索

intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); //搜索结束。重新搜索时,会先终止搜索

intentFilter.addAction(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);//连接蓝牙,断开蓝牙 

intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);

intentFilter.addAction(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);//更改蓝牙名称,打开蓝牙时,可能会调用多次

intentFilter.addAction(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

intentFilter.addAction(BluetoothAdapter.ACTION_REQUEST_ENABLE);

intentFilter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);//搜索模式改变


蓝牙开发,如果考虑到错误的断开蓝牙,unbind,等情况,必须注册好以上的蓝牙广播,其中,PAIRING_REQUEST,是android隐藏的广播,涉及到跳过bind弹框,直接pin,配对,必须要注册。

你可能感兴趣的:(android源码)