Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check Network Coverage in Android before trying to send SMS

I want to create an application for Android smartphones that checks if the phone is in Airplane Mode. If it is, the application gets the phone off the Airplane mode and checks if there is any network connectivity to send a SMS. When I say network connectivity, I mean mobile phone network coverage to send the SMS, I don't want to check for internet connectivity. If there is network connectivity the application will try to send a SMS.

I have managed to do the Airplane Mode check and toggle, but I don't find a way to see if the phone is connected to the cellular network and if there is coverage. I found many examples that check for internet network connectivity, but is not what I need.

Is there any way to check if the phone is connected to the cellular network and if there is coverage to send SMS?

Thanks in advance for your help.

like image 873
michalis Avatar asked Nov 07 '12 18:11

michalis


Video Answer


1 Answers

Use this to check the signal strength:

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

    PhoneStateListener signalListener = new PhoneStateListener() {
        public void onSignalStrengthChanged(int asu) {
            //asu is the signal strength
        }
    };

    telephonyManager.listen(signalListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTH);
like image 61
Luis Cruz Avatar answered Oct 12 '22 01:10

Luis Cruz