确认bluetooth权限已经添加到AndroidManifest.xml文件中
确认BluetoothAdapter已经启用
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Intent enableBluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBluetoothIntent, REQUEST_ENABLE_BT); }
确认已经被发现
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, DISCOVERABLE_DURATION); startActivity(discoverableIntent);
确认已经配对
Set
确认已经开始配对
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress); device.createBond();
上一篇:Android-OnClickListener在设备旋转后不会调用
下一篇:Android-Permissiondenialformediaprovider;WRITE_EXTERNAL_STORAGEalreadyadded”