How to simulate bluetooth on Android emulator

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.

+4
source share
1 answer

BluetoothAdapter.getDefaultAdapter () returns the local default adapter. It returns null if the device does not have Bluetooth capability, and since you are using an emulator that does not support Bluetooth, it returns null.

+3
source

All Articles