Get RSSI in Android Fragments

… accessing RSSI of the connected access point.

ell. Few days back I wanted to build an android application to measure RSSI value of the connected wifi access point (AP). Our final target was to build a propagation model for a classroom, thus we needed many data points (RSSI). I thought some might benefit this tiny feature so here I share my code + insight with you guys.

Object : Develop UI to get the continuously updating RSSI.

  1. Prepair UI layout

First I need to define a field to put the RSSI value. You might know already it is a Textview we need.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<TextView
android:id="@+id/rssi"
android:layout_below="@+id/batteryLevel"
android:layout_width="371dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:paddingLeft="40dp"
android:paddingRight="16dp"


</android.support.constraint.ConstraintLayout>

2. Register receivers to listen RSSI changes

getActivity().registerReceiver(this.myRssiChangeReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));

Add this line to the fragment you are working in. This will bind with myRssiChangeReceiver and RSSI broadcasting changes.

3. Lets implement myRssiChangeReciever method

private BroadcastReceiver myRssiChangeReceiver
= new BroadcastReceiver(){

@Override
public void onReceive(Context arg0, Intent arg1) {
WifiManager wifiMan=(WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
wifiMan.startScan();
int newRssi = wifiMan.getConnectionInfo().getRssi();
textRssi.setText("RSSI Level : "+String.valueOf(newRssi));
}};

This will update textview while listening to the RSSI broadcast.

4. Writing network associated methods [full code]

At the end you will have a RSSI receiver continuously updating the changing values. So in my case I needed some other attributes like connectionn status, bssid,ssid,mac and link speed etc. So all those things also in the above code repository.

Hope you got a help because I could make this working after reading and implementing several solutions.

5. Have a look at my project. Star and contribute.

Happy Coding!

I am an Engineer, I build software.