gpt4 book ai didi

android - 扫描附近的蓝牙设备

转载 作者:太空宇宙 更新时间:2023-11-03 13:36:35 26 4
gpt4 key购买 nike

如果手机打开了蓝牙,应用程序可以读取附近可发现设备的 ID 列表吗?如果是这样,哪个函数返回这样的列表?

谢谢!

最佳答案

看看here

// Create a BroadcastReceiver for ACTION_FOUND
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
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());
}
}
};
// Register the BroadcastReceiver
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy

关于android - 扫描附近的蓝牙设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6479714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com