benarjee bojja
benarjee bojja

Reputation: 348

Android code to get mobile operator name for a phone number entered in edit text

is there any way to find the mobile operator for the number entered by the user in edit text. just like paytm. when user enter the phone number. it will automatically fetch the operator name.

i have following code to find the user device operator name. but i need to find the operator name when user enter the mobile number in edit text.

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

String operatername = telephonyManager.getNetworkOperatorName();

Upvotes: 0

Views: 4042

Answers (3)

Lakpriya Senevirathna
Lakpriya Senevirathna

Reputation: 5119

For any android device

//above 22
     if (Build.VERSION.SDK_INT > 22) {
            //for dual sim mobile
            SubscriptionManager localSubscriptionManager = SubscriptionManager.from(this);

            if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) {
             //if there are two sims in dual sim mobile
                List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
                SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(0);
                SubscriptionInfo simInfo1 = (SubscriptionInfo) localList.get(1);

                final String sim1 = simInfo.getDisplayName().toString();
                final String sim2 = simInfo1.getDisplayName().toString();

            }else{
             //if there is 1 sim in dual sim mobile
                TelephonyManager tManager = (TelephonyManager) getBaseContext()
                        .getSystemService(Context.TELEPHONY_SERVICE);

                String sim1 = tManager.getNetworkOperatorName();

            }

        }else{
            //below android version 22
                    TelephonyManager tManager = (TelephonyManager) getBaseContext()
                            .getSystemService(Context.TELEPHONY_SERVICE);

                    String sim1 = tManager.getNetworkOperatorName();
        }

Upvotes: 0

Aarif Aslam
Aarif Aslam

Reputation: 1123

You can try this

 // Get System TELEPHONY service reference
  TelephonyManager tManager = (TelephonyManager) getBaseContext()
        .getSystemService(Context.TELEPHONY_SERVICE);

  // Get carrier name (Network Operator Name)
  String carrierName = tManager.getNetworkOperatorName();

For more information, refer to this link

Upvotes: 0

Ameer
Ameer

Reputation: 2769

If you want to get the operator name of entered mobile number. You have to use third party software's like InfoBip

With below code, you will get only your sim operating name and other details

    TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
   String carrierName = tManager.getNetworkOperatorName();

Upvotes: 3

Related Questions