diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 87256f87a..c0ba93ad0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -677,21 +677,27 @@ public class BTService extends XWJIService { if ( BOGUS_MARSHMALLOW_ADDR.equals( btAddr ) ) { String btName = addr.bt_hostName; if ( null == s_namesToAddrs ) { - s_namesToAddrs = new HashMap(); + s_namesToAddrs = new HashMap<>(); } - if ( ! s_namesToAddrs.containsKey( btName ) ) { + + if ( s_namesToAddrs.containsKey( btName ) ) { + btAddr = s_namesToAddrs.get( btName ); + } else { + btAddr = null; + } + if ( null == btAddr ) { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if ( null != adapter ) { - Set devs = adapter.getBondedDevices(); - Iterator iter = devs.iterator(); - while ( iter.hasNext() ) { - BluetoothDevice dev = iter.next(); - s_namesToAddrs.put( dev.getName(), dev.getAddress() ); + for ( BluetoothDevice dev : adapter.getBondedDevices() ) { + Log.d( TAG, "%s => %s", dev.getName(), dev.getAddress() ); + if ( btName.equals( dev.getName() ) ) { + btAddr = dev.getAddress(); + s_namesToAddrs.put( btName, btAddr ); + break; + } } } } - - btAddr = s_namesToAddrs.get( btName ); } return btAddr; }