2012-04-13 15 views
0

Ich entwickle eine Android-Anwendung mit Eclipse, um die RSSI-Werte eines Bluetooth-Geräts zurückzugeben. Ich habe das Android Bluetooth Chat-Beispiel an meine Bedürfnisse angepasst, aber ich habe Probleme, den RSSI-Wert zurückzugeben. Nachdem Sie die Schaltfläche scan angeklickt haben, um Geräte in der Nähe zu finden, gibt es den Gerätenamen, die Geräteadresse und den RSSI-Wert zurück. Stattdessen wird null für den RSSI angezeigt.Android meldet "null" für Bluetooth RSSI

if (device.getBondState() != BluetoothDevice.BOND_BONDED) { 
       mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress() + getRssi()); 

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     String action = intent.getAction(); 
     // When discovery finds a device 
     if (BluetoothDevice.ACTION_FOUND.equals(action)) { 
      // Get the BluetoothDevice object from the Intent 
      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
      // Get the Bluetooth RSSI 
      short Rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE); 
      // If it's already paired, skip it, because it's been listed already 
      // Added getRssi() 
      if (device.getBondState() != BluetoothDevice.BOND_BONDED) { 
       mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress() + getRssi()); 
      } 
     // When discovery is finished, change the Activity title 
     } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { 
      setProgressBarIndeterminateVisibility(false); 
      setTitle(R.string.select_device); 
      if (mNewDevicesArrayAdapter.getCount() == 0) { 
       String noDevices = getResources().getText(R.string.none_found).toString(); 
       mNewDevicesArrayAdapter.add(noDevices); 
      } 
     } 
    } 
}; 

Antwort

0

ist, wie ich bin immer RSSI

String deviceRSSI = (intent.getExtras()) erhalten (BluetoothDevice.EXTRA_RSSI) .toString().

private final BroadcastReceiver ActionFoundReceiver = 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)) { 
       BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
       String deviceRSSI = (intent.getExtras()).get(BluetoothDevice.EXTRA_RSSI).toString(); 

       btArrayAdapter.add(device.getName() + "\n" + device.getAddress() + "\n" + deviceRSSI); 
       btArrayAdapter.notifyDataSetChanged(); 
      } 

      if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) { 

      } else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { 

      } 
     } 
    }; 
Verwandte Themen