if (!bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
registerReceiver(bluetoothReceiver, filter);
public static void bluetoothManager() {
if (ActivityCompat.checkSelfPermission(MainApplication.getContext(), Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
return;
}
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null) {
bluetoothAdapter.disable();
}
}
if (ActivityCompat.checkSelfPermission(MainApplication.getContext(), Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
return;
}
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
public static void bluetoothManager() {
if (ActivityCompat.checkSelfPermission(MainApplication.getContext(), Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
return;
}
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// if (bluetoothAdapter != null) {
// bluetoothAdapter.disable();
// }
if (bluetoothAdapter.isEnabled()) {
Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
bondedDevices.forEach(bluetoothDevice -> {
Log.d(TAG, "bluetoothManager " + bluetoothDevice.getName());
});
}
}