3

How to find Sim Network available or not?

I don't want to check internet connection..but I want to check simcard is availble but simcard network is available or not

It is possible to find sim available(Sim State) in simslot . And also mobile internet available or not . But please give me suggestion of how to find network of sim-card is available or not in android programmatically .

Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
Priya Lalani
  • 139
  • 4
  • Duplicate of https://stackoverflow.com/questions/5474089/how-to-check-currently-internet-connection-is-available-or-not-in-android – Sagar Poshiya Feb 25 '19 at 09:41
  • 2
    Possible duplicate of [How to check currently internet connection is available or not in android](https://stackoverflow.com/questions/5474089/how-to-check-currently-internet-connection-is-available-or-not-in-android) – Tamir Abutbul Feb 25 '19 at 09:42
  • possibe duplicate of https://stackoverflow.com/questions/3981007/how-can-i-check-whether-the-sim-card-is-available-in-an-android-device – DTul Feb 25 '19 at 09:55
  • i have tried below link: https://stackoverflow.com/questions/21694440/check-if-a-sim-card-network-service-is-available-or-not . But it gives only sim state but not sim network availability. – Priya Lalani Feb 25 '19 at 10:01
  • https://stackoverflow.com/questions/3981007/how-can-i-check-whether-the-sim-card-is-available-in-an-android-device. this link also give sim state means sim available or not.But not give sim network availability – Priya Lalani Feb 25 '19 at 10:03
  • Use NetworkInfo it describes the status of a network interface of a given type (currently either Mobile or Wi-Fi). - see this : https://developer.android.com/training/basics/network-ops/managing#java – Dhanshri Feb 25 '19 at 10:05
  • @PriyaLalani means you want signal strength of simcard or mobile network right? – Mahesh Keshvala Feb 25 '19 at 10:14
  • yes i want to find signal strength availability – Priya Lalani Feb 25 '19 at 10:18

1 Answers1

2

Check out below code it will provide you signal strength of mobile network:

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);
Mahesh Keshvala
  • 1,261
  • 8
  • 15