Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>Try this code: private ArrayAdapter&lt;String&gt; bondedAdapter = null,newScanedAdapter = null; listViewPairedDevices.setAdapter(bondedAdapter);//oncreate listViewScanedDevices.setAdapter(newScanedAdapter);//oncreate public void doDiscovery(){ setProgressBarIndeterminateVisibility(true); setTitle("Scanning.."); textViewScanedDevices.setVisibility(View.VISIBLE); if(!BluetoothDemoActivity.bluetoothAdapter.isDiscovering()){ BluetoothDemoActivity.bluetoothAdapter.cancelDiscovery(); } BluetoothDemoActivity.bluetoothAdapter.startDiscovery(); }//doDiscovery() ends IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND); this.registerReceiver(myBroadcastReceiver, intentFilter); intentFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); this.registerReceiver(myBroadcastReceiver, intentFilter); Set&lt;BluetoothDevice&gt; bondedSet = BluetoothDemoActivity.bluetoothAdapter.getBondedDevices(); Log.v(BluetoothDemoActivity.LOG, "BluetoothDemo : bondedSet: "+bondedSet); int count = 0; if(bondedSet.size() &gt; 0){ for(BluetoothDevice device : bondedSet){ textViewPairedDevice.setVisibility(View.VISIBLE); bondedAdapter.add(device.getName()+"\n"+device.getAddress()); Log.v(BluetoothDemoActivity.LOG, " count = "+count++); } }else{ bondedAdapter.add("No Devices"); } private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action = intent.getAction(); if(BluetoothDevice.ACTION_FOUND.equals(action)){ buttonScanScanDevices.setVisibility(View.GONE); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if(device.getBondState()!= BluetoothDevice.BOND_BONDED){ newScanedAdapter.add(device.getName()+"\n"+device.getAddress()); } }else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){ setProgressBarIndeterminateVisibility(false); setTitle("Select Device"); if(newScanedAdapter.getCount() == 0){ newScanedAdapter.add("no new device"); } }else if(intent.getAction().equals("android.bluetooth.device.action.PAIRING_REQUEST")){ System.out.println("Pairing request came"); pair(); } } };//BroadcastReceiverends </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload