我用这个project来模拟android模拟器上的蓝牙.
我有2个类,一个启用蓝牙
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BluetoothAdapter.SetContext(this);
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if(adapter==null) {
System.out.println("\nBluetooth NOT supported. Aborting.");
return;
}
if (!adapter.isEnabled()) {
adapter.enable();
}
}
另一次扫描设备并列出它们
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BluetoothAdapter.SetContext(this);
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
System.out.println("\nAdapter: " + adapter);
if(adapter==null) {
System.out.println("\nBluetooth NOT supported. Aborting.");
return;
}
if (!adapter.isEnabled()) {
adapter.enable();
}
if (adapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
adapter.startDiscovery();
}
Set
第二个设备没有检测到任何设备,所以我的代码出了什么问题?
提前致谢.
最佳答案
原文链接:https://www.f2er.com/android/430426.html