1

I want to send SMS when the signal strength is above 5 (I believe that is the minimum signal required to send an SMS). however, i want a reliable method to check this, so checking signal strength seems to be the best bet as it would also cover airplane mode.

An important constraint is that CellSignalStrength was added in API level 17, and need my code to work on API level 8 and above.

Felicia
  • 13
  • 10

1 Answers1

0

There is a thing - SignalStrength in android.telephony.SignalStrenght

The class contains methods to get various network strenght for example: getGsmSignalStrength() which gives you data in range 0-31 31 (99 is invalid)
For CDMA there are other methods like getCdmaDbm() which gives you values in dBm so you should convert them to your scale.
[EDIT]Example of use

telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

final PhoneStateListener mListener = new PhoneStateListener() {
 @Override
 public void onSignalStrengthsChanged(SignalStrength sStrength) {
  //get your signals data
 }
};

// Register the listener for the telephony manager
telephonyManager.listen(mListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
Toumash
  • 1,077
  • 11
  • 27
  • also how do i detect if it is GSM or CDMA? – Felicia Feb 13 '16 at 13:07
  • very easy - just read the docs(link in my answer) :) `isGsm()` :D – Toumash Feb 13 '16 at 13:08
  • the problem is, radio still receives signal regardless of if there is sim inserted – Felicia Feb 13 '16 at 13:13
  • this is going to be a long solution, (yeah i know telephonymanager can detect sim card) can you rather tell me how to detect airplane mode in all api levels? http://stackoverflow.com/questions/35376475/detect-if-sim-card-is-ready-in-android – Felicia Feb 13 '16 at 13:14
  • i have tried that already but it says "system" cannot be resolved as a variable – Felicia Feb 13 '16 at 13:44
  • Check if you reference android.provider.Settings.System not other class – Toumash Feb 13 '16 at 13:47