How to get the bluetooth devices as a list?
You should change your code as below:
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set pairedDevices = mBluetoothAdapter.getBondedDevices();
List s = new ArrayList();
for(BluetoothDevice bt : pairedDevices)
s.add(bt.getName());
setListAdapter(new ArrayAdapter(this, R.layout.list, s));
Obtaining a List of Available Bluetooth Devices on Android
The Bluetooth guide in the Android documentation explains this:
In order to receive information about each device discovered, your application must register a BroadcastReceiver for the ACTION_FOUND intent. The system broadcasts this intent for each device. The intent contains the extra fields EXTRA_DEVICE and EXTRA_CLASS, which in turn contain a BluetoothDevice and a BluetoothClass, respectively.
This sample code is included as well:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Register for broadcasts when a device is discovered.
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
}
// Create a BroadcastReceiver for ACTION_FOUND.
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Discovery has found a device. Get the BluetoothDevice
// object and its info from the Intent.
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
String deviceHardwareAddress = device.getAddress(); // MAC address
}
}
};
If you are working with Bluetooth on Android, I suggest to read that guide carefully. Then read it one more time ;-)
Getting a list of already connected bluetooth devices on Windows 10
You can find the Paired or Connected Bluetooth device by using the DeviceInformation.FindAllAsync(String) method, you can specify the string to be BluetoothDevice.GetDeviceSelectorFromPairingState(true)
or BluetoothDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected)
as the following code.
//Paired bluetooth devices
DeviceInformationCollection PairedBluetoothDevices =
await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelectorFromPairingState(true));
//Connected bluetooth devices
DeviceInformationCollection ConnectedBluetoothDevices =
await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected));
For more information, you can see the topic Enumerate devices and the official DeviceEnumerationAndPairing sample.
How to list bluetooth devices near me using PowerShell
The PowerShell command :
Get-ChildItem -Path HKLM:\SYSTEM\ControlSet001\Services\DeviceAssociationService\State\Store\ | Select-String -Pattern Bluetooth
will print devices already paired :
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\DeviceAssociationService\State\Store\Bluetooth#BluetoothXX:XX:XX:XX:XX:b2-YY:YY:YY:YY:YY:YY
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\DeviceAssociationService\State\Store\Bluetooth#BluetoothXX:XX:XX:XX:XX:b2-ZZ:ZZ:ZZ:ZZ:ZZ:ZZ
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\DeviceAssociationService\State\Store\BluetoothLE#BluetoothLEXX:XX:XX:XX:XX:b2-WW:WW:WW:WW:WW:WW
The XX:XX:XX:XX:XX
values is your Bluetooth MAC adress.
Web bluetooth, get paired devices list
There is not currently a way to get a list of Bluetooth devices in Chrome. However, I am working on implementing a getDevices()
method for Bluetooth. Please follow the status in Chrome Platform Status
6/22/20 Edit:
I recently implemented a new permissions backend as well as two APIs that will enable previously permitted Bluetooth devices to be used.
The new permissions backend is implemented behind the chrome://flags/#enable-web-bluetooth-new-permissions-backend. The new backend will persist device permissions granted through requestDevice()
until the permission is reset in Site Settings or the Page Info dialog box.
The getDevices()
and watchAdvertisements()
are implemented behind the chrome://flags/#enable-experimental-web-platform-features flag for Chrome 85.0.4165.0 or greater. The recommended use of these APIs is to use getDevices()
to retrieve an array of permitted BluetoothDevices and then calling watchAdvertisements()
on these devices to start a scan. When advertisement packets are detected from the devices, the advertisementreceived
Event will be fired on the device that it corresponds to. At this point, the Bluetooth device is in range and can be connected to.
Please give this new feature a try, and file any bugs at https://crbug.com using the Blink>Bluetooth component.
Related Topics
Nsurlsession With Nsblockoperation and Queues
Navigation Bar With Uiimage For Title
How to Animate the Background Color of a Uilabel
Detect iOS App Entering Background
Library Not Loaded: @Rpath/Fblpromises.Framework/Fblpromises iOS 13.3.1
How to Disable Copy Paste Option from Uitextfield Programmatically
Detecting Color of Iphone/Ipad/Ipod Touch
Run Code Only After Asynchronous Function Finishes Executing
What Are the Dangers of Method Swizzling in Objective-C
How to Write Dispatch_After Gcd in Swift 3, 4, and 5
How to Set the Width of a Cell in a Uitableview in Grouped Style
Getting List of Files in Documents Folder
Customize Uitableview Header Section
Subclass Uiapplication With Swift
How to Iterate For Loop in Reverse Order in Swift
Getting All Cookies from Wkwebview