Я использовал этот проект для имитации bluetooth на эмуляторе Android.
У меня есть 2 класса, один из которых позволяет bluetooth
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);
}
}
второе устройство не обнаруживает никаких устройств, так что не так с моим кодом?
заранее спасибо.