2011-08-15 6 views
1

저는 대부분의 BT 상태를 처리하는 작은 BluetoothReceiver를 작성했습니다.안드로이드 블루투스, LG에서 빈 이름 장치를 찾습니다.

수신자가 대부분의 시나리오에서 작동하지만, 조사해 보았지만 경우에 따라 이름이 비어있는 문자열이있어서 한 장치를 다른 장치와 구분할 수 없습니다. 여기

는 발견의 코드 조각과를 백업하는 로그의 조각입니다 :

참고 : BT 어댑터가 꺼져 있고 두 번째 감지 이전되고있다.

또 다른 편지 :이 시나리오는 정확히 매 초마다 시간을 발생합니다.

08-15 22:54:16.500: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: [bbbb:Demo gizmo 2], 5a0204, 6C:0E:0D:77:B0:96 
08-15 22:54:16.578: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: [aaaa:Demo gizmo 1], 5a020c, 00:26:CC:81:AF:AD 
08-15 22:54:33.820: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: Zomaar Iemand, 5a0204, 20:21:A5:C0:CF:6F 

또 다른 로그인 이름없는 :

08-15 22:54:34.304: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: , 5a0204, 00:26:E2:66:31:30 
08-15 22:54:36.882: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: , 5a0204, 6C:0E:0D:77:B0:96 
08-15 22:54:38.601: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: , 5a020c, 00:26:CC:81:AF:AD 
08-15 22:54:39.820: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: , 520204, 78:CA:04:83:45:CD 
이름이 발견 처음, 두 번째 시간은 장치 이름에는 이름

public class BT_Receiver 
     extends BroadcastReceiver { 
... 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     if (deviceDetectionListener.allDevicesFound()) 
      return; 
     String action = intent.getAction(); 
     if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { 
      int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1); 
      state = BT_State.getInstanceForState(newState); 
      Toast.makeText(activity, state.name(), Toast.LENGTH_SHORT).show(); 
      if (state == BT_State.On && enableAndDiscover) 
       startDiscoveringDevices(); 
      return; 
     } 
     if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) { 
      state = BT_State.Discovering; 
      Toast.makeText(activity, state.name(), Toast.LENGTH_SHORT).show(); 
      return; 
     } 
     if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { 
      state = BT_State.On; 
      Toast.makeText(activity, "Finished discovery", Toast.LENGTH_SHORT).show(); 
      return; 
     } 
     if (BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(action)) { 
      int discoveryDuration = intent.getIntExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, -1); 
      state = BT_State.Advertising; 
      Toast.makeText(activity, state.name() + ", duration: " + discoveryDuration, Toast.LENGTH_SHORT).show(); 
     } 
     if (!BluetoothDevice.ACTION_FOUND.equals(action)) 
      return; 
     BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
(Look at the LOG RESULT)  
        Log.i(TAG, "Bluetooth device found: " + device.getName() + ", " + device.getBluetoothClass() + ", " + device.getAddress()); 
     deviceDetectionListener.newDeviceDetected(device); 
     if (deviceDetectionListener.allDevicesFound()) 
      detectionCompleted(); 
    } 

... 
} 

로그 없다

미리 감사드립니다.

Adam.

답변

0

이것은 아마도 버그가 아니며 해결 방법을 찾았습니다. 즉, 장치에 이름이 없으면 저장하지 않고 장치가없는 경우 다시 쿼리를 실행하십시오.

관련 문제