Ответ 1
Здесь приведен полный пример для обнаружения устройств.
Вы можете использовать MAC-адрес как уникальный идентификатор.
О силе сигнала. Думаю, вы должны использовать RSSI (индикатор признака сигнала приема).
Мне нужно получить список доступных Bluetooth-устройств в этой области, используя Google Android 2.1.
Дело в том, что мне не нужен список этих устройств, мне нужен уникальный идентификатор для каждого найденного устройства, и мне нужен индикатор, как "хороший" сигнал получен (например, "уровень" в Android. wifi.ScanResult)... Как это сделать?
Здесь приведен полный пример для обнаружения устройств.
Вы можете использовать MAC-адрес как уникальный идентификатор.
О силе сигнала. Думаю, вы должны использовать RSSI (индикатор признака сигнала приема).
Проверьте код ниже:
Начальный поиск
mBluetoothAdapter.startDiscovery();
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
//Finding devices
if (BluetoothDevice.ACTION_FOUND.equals(action))
{
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
}
};
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
Вызов метода bluetoothScanning, требуется контекст
void bluetoothScanning(){
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
context.registerReceiver(mReceiver, filter);
final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.startDiscovery();
}
// 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
Log.i("Device Name: " , "device " + deviceName);
Log.i("deviceHardwareAddress " , "hard" + deviceHardwareAddress);
}
}
};
Результат
Название: LE-Bose Revolve+ SoundLink, устройство, аппаратное обеспечение, адрес: MAC.....
Пожалуйста, обратитесь, это поможет обнаружить Bluetooth поблизости
https://www.linkedin.com/feed/update/urn:li:activity:6546090437717880832
Это образец рис, как выглядит пользовательский интерфейс.
https://www.linkedin.com/feed/update/urn:li:activity:6546092313507090432