Check your network coverage on 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 so, the application pulls the phone out of airplane mode and checks if there is a network connection to send SMS. When I talk about connecting to a network, I mean the coverage of a mobile network for sending SMS, I do not want to check the Internet connection. If there is a network connection, the application will try to send SMS.

I managed to check the flight mode and switch, but I did not find a way to find out if the phone is connected to the cellular network, and if there is coverage. I found many examples that test Internet connectivity, but that is not what I need.

Is there a way to check if the phone is connected to the cellular network and is there coverage for sending SMS?

Thanks in advance for your help.

+4
source share
1 answer

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); 
+5
source

Source: https://habr.com/ru/post/1444639/


All Articles