我需要獲得該地區可用的藍牙設備列表使用谷歌Android 2.1。如何在android中掃描可用的藍牙設備?
事情是,我不只需要這些設備的列表,我需要爲每個設備找到一個唯一的ID,我需要一個指標,如何「好」的信號接收(如「水平」在Android .wifi.ScanResult)...我該怎麼做?
我需要獲得該地區可用的藍牙設備列表使用谷歌Android 2.1。如何在android中掃描可用的藍牙設備?
事情是,我不只需要這些設備的列表,我需要爲每個設備找到一個唯一的ID,我需要一個指標,如何「好」的信號接收(如「水平」在Android .wifi.ScanResult)...我該怎麼做?
退房代碼:
開始搜索
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-百色旋轉+的SoundLink deviceHardwareAddress :MAC 04:52:C7:D1:B2:76
.....
有人對此RSSI有經驗嗎?我在這裏有點不安全,因爲這被定義爲一個常量? – xenonite 2010-07-03 10:35:53
你的第一個鏈接 - http://developer.android.com/guide/topics/wireless/bluetooth.html#FindingDevices已經死了 – Dayan 2016-05-24 21:01:22
鏈接已經打破了 – Charlie 2016-07-24 21:14:14