80,362
社区成员
发帖
与我相关
我的任务
分享
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
final BluetoothDevice device = adapter.getRemoteDevice("硬件设备的MAC地址 如 : 04:33:3A:12:15:5F");
BluetoothGattCallback bluetoothGattCallbackOne = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.i("gwh", status + "---" + newState);
if (status == BluetoothGatt.GATT_SUCCESS) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
Log.i("gwh", "连接成功了.");
//搜索Service
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
Log.i("gwh", "连接失败了.");