I used this project to simulate bluetooth on an Android emulator.
I have 2 classes, one of which allows 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(); } }
another scan of devices and their list
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); } }
the second device does not detect any devices, so what's wrong with my code?
thanks in advance.
source share