How to retrieve Bluetooth device info with Android Bluetooth device picker?
Date : March 29 2020, 07:55 AM
will help you Here is the test code that I am using : , Try this code: private final BroadcastReceiver mBluetoothPickerReceiver = new BluetoothConnectActivityReceiver(this);
void connectToService(String defaultAdapter) {
if (defaultAdapter == null) {
registerReceiver(mBluetoothPickerReceiver, new IntentFilter(BluetoothDevicePicker.ACTION_DEVICE_SELECTED));
startActivity(new Intent(BluetoothDevicePicker.ACTION_LAUNCH)
.putExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false)
.putExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE, BluetoothDevicePicker.FILTER_TYPE_ALL)
.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS));
} else {
mCardroid.getCardroidService().connectTo(defaultAdapter);
}
}
public class BluetoothConnectActivityReceiver extends BroadcastReceiver {
private BluetoothConnectActivity bluetoothConnectActivity;
public BluetoothConnectActivityReceiver(BluetoothConnectActivity bluetoothConnectActivity) {
this.bluetoothConnectActivity = bluetoothConnectActivity;
}
@Override
public void onReceive(Context context, Intent intent) {
if(BluetoothDevicePicker.ACTION_DEVICE_SELECTED.equals(intent.getAction())) {
context.unregisterReceiver(this);
BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
bluetoothConnectActivity.connectToService(device.getAddress());
}
}
}
|
Bluetooth - Is a sending a message over Bluetooth to a hardware device from a PC and from an Android Device the same thi
Date : March 29 2020, 07:55 AM
it helps some times Seeems like you are using the Bluetooth Serial port profile from the PC to connect to your hardware. And if you use the same profile you can send the data from any device and the same application on your hardware should handle it. So yes you can use the android bluetooth socket interface to crreate and connect to the hardware and it should also work.
|
Android: How to find out name of the bluetooth device connected?
Date : March 29 2020, 07:55 AM
To fix this issue Basically im trying 2 things here, Im trying to start a toast when my bluetooth device is connected to a particular device (so need to check if that is the particular bluetooth name), if that is the particular device then i want to show a toast when connected to that particular bluetooth device. I also want to show a toast when my bluetooth is disconnected to that particular bluetooth device. Here's my code: in manifest.xml , Change your broadcast receiver to: private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
//you can get name by device.getName()
} else if (BluetoothAdapter.ACL_DISCONNECTED
.equals(action)) {
}
}
};
|
Android - Bluetooth LE can't find any device
Date : March 29 2020, 07:55 AM
it fixes the issue The solution for my problem was to understand more deeply how BLE works. What I needed to realize is that BLE capable devices are not showing themselves automatically as for example devices that you find in the Bluetooth settings screen - I have to manually start the advertising of the device. So I've searched for an example and found this tutorial: Tuts+ - BluetoothLEAdvertising. With this example I've started to advertise one of the devices, and then I could find that device on another one. So, it was my bad... :) This also means that currently the scan's result is not depending on manufacturer, API level, build version, etc... But I can imagine that these factors will possibly cause some troubles in the future...
|
How to detect bluetooth device and get the bluetooth address of detected device from android app
Date : March 29 2020, 07:55 AM
|