title: How to get a RSSI of bluetooth
body: <p>I am trying to get the RSSI of the bluetooth connection. First i thought to display the RSSI of all nearby devices, so i checked the internet - got some information of the bluetooth classes and checked some examples. I tried a lot of thing, but with no success. I am at stage that I cant understand where exactly is the problem.</p>
  
  <p>The target SDK is 29 and min SDK is 19. I am testing it on Android 10 (SDK 29)</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>package com.example.myapplication;
  
  import android.bluetooth.BluetoothAdapter;
  import android.bluetooth.BluetoothDevice;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.graphics.BlendMode;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.widget.CompoundButton;
  import android.widget.TextView;
  
  import android.widget.ToggleButton;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import java.util.Set;
  
  public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
  
  BluetoothAdapter BA;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
  
          BA = BluetoothAdapter.getDefaultAdapter();
          BA.startDiscovery();
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.options, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle item selection
          switch (item.getItemId()) {
              case R.id.settings:
                  Intent intent = new Intent(this, SettingsActivity.class);
                  startActivity(intent);
                  return true;
              default:
                  return super.onOptionsItemSelected(item);
          }
      }
  
  
      private final BroadcastReceiver receiver = new BroadcastReceiver(){
          @Override
          public void onReceive(Context context, Intent intent) {
  
              String action = intent.getAction();
              if(BluetoothDevice.ACTION_FOUND.equals(action)) {
                  int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
                  TextView rssi_msg = (TextView) findViewById(R.id.textView1);
                  rssi_msg.setText(rssi_msg.getText() + "" + rssi + "dBm\n");
              }
          }
      };
  
  }
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.myapplication"&gt;
  
      &lt;uses-permission android:name="android.permission.BLUETOOTH" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".Main2Activity"&gt;&lt;/activity&gt;
          &lt;activity
              android:name=".SettingsActivity"
              android:label="@string/title_activity_settings"
              android:parentActivityName=".MainActivity" /&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>