2012-04-13 17 views
0

Eclipseを使用してAndroidデバイスを開発し、BluetoothデバイスのRSSI値を返します。私は自分のニーズに合わせてAndroidのBluetoothチャットの例を変更しましたが、RSSI値を返すのに問題があります。近くのデバイスを検出するためにscanボタンを押すと、デバイス名、デバイスアドレスが返され、RSSI値を返すと想定されますが、代わりにRSSIの場合はnullと表示されます。私はそれを自分自身を試していないが、多分このSO答えは助けるBluetoothで「null」を返すAndroid 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); 
      } 
     } 
    } 
}; 

答えて

0

これは私がRSSI

文字列deviceRSSI = (intent.getExtras())を取得(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)) { 

      } 
     } 
    }; 
関連する問題