我需要使用 google android 2.1 获取该地区可用蓝牙设备的列表。
问题是,我不仅需要这些设备的列表,我还需要找到每个设备的唯一 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);
关于android - 如何在android范围内扫描可用的蓝牙设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3170805/