我是 android 新手。我想开发一个应用程序,通过编程方式使用蓝牙来查找范围内的设备。如果有人有想法,请给我一些示例代码。
Find The Devices in the Range by using Bluetooth programmatically.
是的,你可以使用以下方法来做到这一点广播接收器 http://developer.android.com/reference/android/content/BroadcastReceiver.html,看看下面的代码,它会对你有帮助。
开始搜索
mBluetoothAdapter.startDiscovery();
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
找到设备
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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)