Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Signal Strength in Android

I want to get the Signal Strength of the Device at the point I hit the API call. I have searched on all the related threads and I am not successful yet.

So I would like to get the signal strength like

SignalStrength ss = null  ; // some initialization  int n = ss.getGsmSignalStrength(); 

But while using this, it is obvious that I will get null pointer exception since I have initialised SignalStrength as null. But I don't know how to initialise this.

Also that I don't want to use PhoneStateListener because it is triggered only if the signal changes.

I am getting the Signal Strength using the below code

TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0); CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength(); cellSignalStrengthGsm.getDbm(); 

But I don't want to use CellSignalStrength because it is only added in API Level 17 and will not work under 17. I want the code to work on API Level 7+.

Or is there any other method, so that I could get the signal strength at the point of hitting the API call?

like image 789
VIGNESH Avatar asked Nov 06 '13 06:11

VIGNESH


People also ask

Is there any app to see signal strength of all networks available in Android?

Open Signal This is an iphone signal strength app, that is also available at the Playstore for Android users to enjoy. It will check your 3G, 4G or Wifi signal, giving you comprehensive data on all the devices, routers and mobile phone antennas.

How do I put my Android in field test mode?

To open the field test mode on an Android Phone, start the phone app, enter *#*#4636#*#* and after you enter the last asterisk a menu displays with options for Phone Information, Battery Information, Battery History, Usage Statistics, and Wifi Information.

How do you read signal strength?

Signal strength is represented in -dBm format (0 to -100). This is the power ratio in decibels (dB) of the measured power referenced to one milliwatt. The closer the value is to 0, the stronger the signal. For example, -41dBm is better signal strength than -61dBm.


1 Answers

Define Variables:

TelephonyManager mTelephonyManager; MyPhoneStateListener mPhoneStatelistener;    int mSignalStrength = 0; 

Then add this class to your code:

class MyPhoneStateListener extends PhoneStateListener {       @Override      public void onSignalStrengthsChanged(SignalStrength signalStrength) {          super.onSignalStrengthsChanged(signalStrength);          mSignalStrength = signalStrength.getGsmSignalStrength();          mSignalStrength = (2 * mSignalStrength) - 113; // -> dBm                 }  } 

and in your onCreate method use:

mPhoneStatelistener = new MyPhoneStateListener(); mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mTelephonyManager.listen(mPhoneStatelistener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); 
like image 148
Ingo Avatar answered Sep 28 '22 03:09

Ingo