4
我用这个project来模拟android模拟器上的蓝牙。
我有2个班一个启用蓝牙如何模拟Android模拟器上的蓝牙
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<BluetoothDevice> devices = adapter.getBondedDevices();
for (BluetoothDevice device : devices) {
System.out.println("Found device: " + device);
}
}
第二设备没有检测到任何设备,所以有什么错我的代码?
在此先感谢。
您需要在代码中注明一些日志,看看发生了什么,正在运行什么方法等 – Blundell 2011-06-08 08:13:31
我这样做,并意识到“设备”设置它的长度为零! – Aboelnour 2011-06-08 08:15:01