我是android的新手.我想开发一个应用程序,通过编程方式使用蓝牙找到该范围内的设备.如果有任何想法,请给我一些示例代码.
Find The Devices in the Range by using Bluetooth programmatically.
是的,您可以使用BroadcastReceiver执行此操作,请查看以下代码,它会对您有所帮助.
开始搜索
mBluetoothAdapter.startDiscovery();
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Run Code Online (Sandbox Code Playgroud)
找到一个设备
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5487 次 |
| 最近记录: |