Android bluetooth scan of already paired - android

I'm making an Android application that scan all device in the room and connect/pair to the device automatically or not, depending on the name prefix.
I tried some examples and the scan result return only unpaired devices. So I need that the result of the scan return also already paired devices. Is it possible on Android ? (I already done this on windows)

Yes. You need to get the local bluetooth adapter
Adapter = BluetoothAdapter.getDefaultAdapter();
get paired devices into a private set Bluetooth device
devicepair = Adapter.getBondedDevices();
And then from that point it should be a simple for loop to add device pair to a list view that shows your bluetooth devices
for(BluetoothDevice : devicepair)
//your array name or whatever inside the for loop
listviewarray.add(devicepair.getName());

Related

Find all Bluetooth Devices within range of the phone

I know that I can discover new devices with BluetoothAdapter.startDiscovery()
IntentFilter(BluetoothDevice.ACTION_FOUND) and BroadcastReceiver.
And get all paired Bluetooth Devices via BluetoothAdapter.getBondedDevices().
But if I pair a device I don't know if it's reachable or not.
Is there a way to get all devices within a reach of phone? I don't even need BluetoothDevice Objects, I won't connect with them, I just want their addresses.
You can exclude the bonded devices from the array/list of the devices found.
Something like this:
if (device.bondState != BluetoothDevice.BOND_BONDED) {
mDevicesArrayAdapter.add(device.name + "\n" + device.address)
}

How to scan specific Bluetooth device and get information from it in Android?

I try to build a project that can get Bluetooth rssi from specific devices. However, I'm stuck on that. Is there any way to filter and specify the scanning results and then continuously get information from the chosen Bluetooth devices?
Many thanks.
Yes
You can filter using device MAC address in android
//lets say i have a device i got by searching BT devices
BluetoothDevice device;
String mac = "00:11:22:AA:BB:CC"
if(mac.equals(device.getAddress)){
// my device found
}
public String getAddress ()
Added in API level 5
Returns the hardware address of this BluetoothDevice.
Bluetooth hardware address as string
for more see Android BluetoothDevice doc

How to determine model of smartphone connected to my device

I want to know is there any way to determine model of smartphone connected to my android device via bluetooth programmatically? I know how to make bluetooth connection between two android devices, but how to request information of smartphone's model? Thanks.
Use the BluetoothManager for this task:
List<BluetoothDevice> connectedDevices = this.getSystemService(Context.BLUETOOTH_SERVICE)
.getConnectedDevices(BluetoothProfile.GATT); //or BluetoothProfile.GATT_SERVER
for(BluetoothDevice bd : connectedDevices){
String remoteName = bd.getName();
//do something
}

Discovering vendor-specific bluetooth devices only

Need to discover or search for Bluetooth devices of certain "vendor-specific" devices.
"vendor-specific" means all devices will have similar starting bits in their "MAC" address
For example, I want to search only for devices whose MAC address starts with 12:34:56:
It should search only for specific series of MAC addresses and list them.
Perform a full discovery, then filter using BluetoothDevice.getAddress()
// Define Vendor ID Prefix
public static final String VENDOR_ID = "12:34:56:"
// First, do a full discovery...
BluetoothAdapter.getDefaultAdapter().startDiscovery()
//...
// Then, for each device returned from discovery...
if ( device.getAddress().startsWith(VENDOR_ID) ) {
// Do Something
}
My Explanation will be based on the BluetoothChat example from the Android SDK, hopefully this is ok, otherwise I would need to write a lot more. If you haven't seen the BluetoothChat example, go take a look, it's really nice!
If you want to use a device where you don't know the complete adress, you'll have to do a complete discovery with BluetoothAdapter.startDiscovery() and search the received addresses for the ones you want to.
If you know the complete address of the device you want to connect to you can directly connect to this device with BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address)

Problem in storing the list of bluetooth devices in Android App

I'm creating Bluetooth custom application, but I have a small issue. When in my receiver I detect a device, I want to store this device in Set<BluetoothDevice>.
But my receiver is a different class, and when I write this code:
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
ClassName.SetVar.add(device);
Then it is showing an exception. I want to store all detecting device in a variable and want to use in diffrent thread to establish a connection.
Finally i solved by using a constructor

Categories

Resources