Get GSM Signal Strength – Android Tutorials
How to get the Quality of the Signal received by our phone. This tutorial we’ll teach you how to get the signal strength you receive at any moment from your Carrier provider. Lets start with the Tutorial: We are going to learn how to add a listener to the telephony class, and how to get the CINR (Signal Quality) from this listener. We need to add permissions for the Activity Add the fallowing permission: android.permission.CHANGE_NETWORK_STATE The “AndroidManifest.xml” file should looks as below:< ?xml version="1.0" encoding="utf-8"?>
< ?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Firstdroid.Tutorial.GetGsmSignalStrength"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".GetGsmSignalStrength"
android:label="@string/app_name">
<intent -filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent>
</activity>
</application>
<uses -sdk android:minSdkVersion="4" />
<uses -permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses>
</manifest>
Now lets start with the code.
All the explanation are already built in inside the code, please read the remarks.
Add the imports we will need
< ?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Firstdroid.Tutorial.GetGsmSignalStrength"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".GetGsmSignalStrength"
android:label="@string/app_name">
<intent -filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent>
</activity>
</application>
<uses -sdk android:minSdkVersion="4" />
<uses -permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses>
</manifest>
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.widget.Toast;
Now the class with the fallowing methods:
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.widget.Toast;
- onResume, Called when application restarts after being minimized
- onPause, Called when the application is being minimized
- onCreate, Called when the application is first started
- private class MyPhoneStateListener, Called to create the listener
public class GetGsmSignalStrength extends Activity
{
/* This variables need to be global, so we can used them onResume and onPause method to
stop the listener */
TelephonyManager Tel;
MyPhoneStateListener MyListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Update the listener, and start it */
MyListener = new MyPhoneStateListener();
Tel = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* Called when the application is minimized */
@Override
protected void onPause()
{
super.onPause();
Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
}
/* Called when the application resumes */
@Override
protected void onResume()
{
super.onResume();
Tel.listen(MyListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* —————————– */
/* Start the PhoneState listener */
/* —————————– */
private class MyPhoneStateListener extends PhoneStateListener
{
/* Get the Signal strength from the provider, each tiome there is an update */
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength)
{
super.onSignalStrengthsChanged(signalStrength);
Toast.makeText(getApplicationContext(), "Go to Firstdroid!!! GSM Cinr = "
+ String.valueOf(signalStrength.getGsmSignalStrength()), Toast.LENGTH_SHORT).show();
}
};/* End of private Class */
}/* GetGsmSignalStrength */
That is all.
You should now see the fallowing:
This is another Firstdroid tutorial.
Any Question, Comment or Remark, please come to our forum at: Firstdroid Forum
Enjoy,
Firstdroid.
{
/* This variables need to be global, so we can used them onResume and onPause method to
stop the listener */
TelephonyManager Tel;
MyPhoneStateListener MyListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Update the listener, and start it */
MyListener = new MyPhoneStateListener();
Tel = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* Called when the application is minimized */
@Override
protected void onPause()
{
super.onPause();
Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
}
/* Called when the application resumes */
@Override
protected void onResume()
{
super.onResume();
Tel.listen(MyListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* —————————– */
/* Start the PhoneState listener */
/* —————————– */
private class MyPhoneStateListener extends PhoneStateListener
{
/* Get the Signal strength from the provider, each tiome there is an update */
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength)
{
super.onSignalStrengthsChanged(signalStrength);
Toast.makeText(getApplicationContext(), "Go to Firstdroid!!! GSM Cinr = "
+ String.valueOf(signalStrength.getGsmSignalStrength()), Toast.LENGTH_SHORT).show();
}
};/* End of private Class */
}/* GetGsmSignalStrength */





Hello,I’m Hiroaki.
Because the method of API level 7 is used, it is not possible to execute it though minSDK 4 (your code is minSDK four).
Will you know the method by which CDMA information can be acquired with android1.6?
My best regards.
How we can strength in value out side?
I have done like this;
int singalStrength =0;
public void onCreate(Bundle savedInstanceState) {
……
myListener = new MyPhoneStateListener();
telManager = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
telManager.listen(myListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
System.out.println(“==###===” + singalStrength);
System.out.println(“==@@@===” + myListener.singalStenths);
}
private class MyPhoneStateListener extends PhoneStateListener
{
public int singalStenths =0;
/* Get the Signal strength from the provider, each tiome there is an update */
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength)
{
super.onSignalStrengthsChanged(signalStrength);
singalStrength = signalStrength.getGsmSignalStrength();
singalStenths = signalStrength.getGsmSignalStrength();
System.out.println(“=======” + singalStrength);
Toast.makeText(getApplicationContext(), “Go to Firstdroid!!! GSM Cinr = ”
+ String.valueOf(signalStrength.getGsmSignalStrength()), Toast.LENGTH_SHORT).show();
}
};/* End of private Class */
But always I got “0″ in onCreate method.
Please help me.
Thanks in advance
Sir, can you please help me add this code source into a Wallpaper Service.
Please have a tutorial regarding it. Thank You!
great work, but first xml line is givin error (( can you pls upload a fully package sample??
one more issue, btw
instead of this:
should be this (workin):
I am trying to write a very simple Android application that checks the signal strength of the current cell. So far, I have only found something called getNeighboringCellInfo(), but I’m not really sure if that includes the current cell.
Is there a problem with the Samsung Galaxy S II? I have run your code and tried all sorts or variations but I always get 99 as the signal strength. Phone is working fine otherwise.
Developing in Eclipse.
HELP!!
Hello Sir,
could you tell me maybe, how I could change the color of my background when the signal gets low?
like, when i have less signal than my background should turn for example red. and if i have good signal my background should turn yellow or something like this… please help me sir its very important!
Thank you
It would have been better to have the method(s) of PhoneStateListener in a separate class and use Intent to pass the signal strength back to the Activity class. The code is neater this way.
Also, the example forgot about signalStrength.isGsm() check and the getGsmSignalStrength() method will only return the Arbitrary Strength Unit (ASU) so you need to calculate the actual signal strength like: (-113 + 2 * ASU).
But always I got “0″ in onCreate method.