Java 打印可用蓝牙设备的列表
我正在尝试让我的应用程序在打开活动时打印可用蓝牙设备的列表 首先,我在设备上启用蓝牙:Java 打印可用蓝牙设备的列表,java,android,bluetooth,Java,Android,Bluetooth,我正在尝试让我的应用程序在打开活动时打印可用蓝牙设备的列表 首先,我在设备上启用蓝牙: public class Home extends AppCompatActivity { TextView textView3; private static final int REQUEST_ENABLE_BT = 1; BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); @Override protected vo
public class Home extends AppCompatActivity {
TextView textView3;
private static final int REQUEST_ENABLE_BT = 1;
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
textView3 = (TextView) findViewById(R.id.textView3);
if (btAdapter == null) {
textView3.append("\nBluetooth not supported. Aborting.");
}
}
然后,我尝试将找到的任何设备添加到适配器
private final BroadcastReceiver bReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
//add device to the adapter
btAdapter.add(device.getName(), device.getAddress());
}
}
};
我知道某个地方应该有startDiscovery()调用,但我在理解其他在线答案时遇到了困难。此外,由于某些原因,无法识别我的btAdapter.add()
任何帮助都将不胜感激
由于某些原因,无法识别我的btAdapter.add()
因为BluetoothAdapter中没有这样的方法
我知道某个地方应该有startDiscovery()调用,但我在理解其他在线答案时遇到了困难
一旦您确定设备支持蓝牙且蓝牙已从设备设置打开,您可以调用startDiscovery