使用广播接收器(Broadcast Receiver):Android系统会发送一系列蓝牙连接状态的广播,开发者可以注册广播接收器来监听这些广播,并根据接收到的广播来判断蓝牙设备的连接状态。常用的广播包括ACTION_ACL_CONNECTED(设备已连接)、ACTION_ACL_DISCONNECTED(设备已断开连接)等。 使用回调函数(Callback):Android提供了BluetoothGattCall...
在您的AndroidManifest中声明<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /...
case BluetoothDevice.ACTION_ACL_CONNECTED: break; case BluetoothDevice.ACTION_BOND_STATE_CHANGED: //绑定状态返回 break; case BluetoothDevice.ACTION_FOUND: //扫描到的设备 BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); break; } } }; 1. 2. 3. 4. 5. 6. 7. ...
ACTION_CONNECTION_STATE_CHANGED,ACTION_CONNECTION_STATE_CHANGED,ACTION_ACL_CONNECTED,ACTION_ACL_DISCONNECTED 如果应用接收这些蓝牙事件的广播,则用户体验不太可能受到影响。 ACTION_CARRIER_CONFIG_CHANGED,TelephonyIntents.ACTION_*_SUBSCRIPTION_CHANGED,“TelephonyIntents.SECRET_CODE_ACTION”,ACTION_PHONE_STATE_CHANG...
Log.d("aaa", device.getName() + " ACTION_ACL_DISCONNECTED"); } BluetoothClass 可以获取蓝牙设备的类型 如果想获取当前已连接上的所有蓝牙设备,可以在这两个广播中手动维护一个连接设备的列表。 像下面这样: /*** 记录当前正在连接的所有蓝牙输入设备*/publicList<BluetoothDevice> connectedBluetoothDevices ...
*/intentFilter.addAction(BluetoothDevice.ACTION_FOUND);//搜索蓝压设备,每搜到一个设备发送一条广播intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);//配对开始时,配对成功时intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);//配对时,发起连接intentFilter.addAction(BluetoothDevice....
ACTION_LOCALE_CHANGED ACTION_USB_ACCESSORY_ATTACHED, ACTION_USB_ACCESSORY_DETACHED, ACTION_USB_DEVICE_ATTACHED, ACTION_USB_DEVICE_DETACHED ACTION_HEADSET_PLUG ACTION_CONNECTION_STATE_CHANGED, ACTION_CONNECTION_STATE_CHANGED, ACTION_ACL_CONNECTED, ACTION_ACL_DISCONNECTED ...
connected before the application starts, // ACTION_ACL_CONNECTED will not be received,&...
/*** 有注释的广播,蓝牙连接时都会用到*/intentFilter.addAction(BluetoothDevice.ACTION_FOUND);//搜索蓝压设备,每搜到一个设备发送一条广播intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);//配对开始时,配对成功时intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);//配对时,发起连...
ACTION_CONNECTION_STATE_CHANGED,ACTION_CONNECTION_STATE_CHANGED,ACTION_ACL_CONNECTED,ACTION_ACL_DISCONNECTED如果应用收到这些蓝牙事件的广播,则用户体验不太可能会受到影响。 ACTION_CARRIER_CONFIG_CHANGED,TelephonyIntents.ACTION_SUBSCRIPTION_CHANGED,TelephonyIntents.SECRET_CODE_ACTION,ACTION_PHONE_STATE_CHANGED,ACT...