fhucho
fhucho

Reputation: 34550

How to find out carrier's name in Android

How can I find out carrier's name in Android?

Upvotes: 85

Views: 77980

Answers (5)

Kumar Santanu
Kumar Santanu

Reputation: 701

You could try something LIKE THIS - Latest Working and improved code

IN JAVA

String getCarrierName() {
  try {
     TelephonyManager manager = (TelephonyManager) OneSignal.appContext.getSystemService(Context.TELEPHONY_SERVICE);
     // May throw even though it's not in noted in the Android docs.
     // Issue #427
     String carrierName = manager.getNetworkOperatorName();
     return "".equals(carrierName) ? null : carrierName;
  } catch(Throwable t) {
     t.printStackTrace();
     return null;
  }
}

IN KOTLIN

 fun getCarrierName(): String? {
    return try {
        val manager =
            App.instance.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
        // May throw even though it's not in noted in the Android docs.
        // Issue #427
        val carrierName = manager.networkOperatorName
        if ("" == carrierName) null else carrierName
    } catch (t: Throwable) {
        t.printStackTrace()
        null
    }
}

Upvotes: 0

Sir Codesalot
Sir Codesalot

Reputation: 7293

A Kotlin null safe implementation:

val operatorName = (context.getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager)?.networkOperatorName ?: "unknown"

Upvotes: 1

velval
velval

Reputation: 3312

In case one needs the Carrier name of the Operator as shown on the Notifications bar as @Waza_Be asked. One could use the getSimOperatorName method instead, as several Telcos sublease their Network to other companies.

TelephonyManager telephonyManager = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
String simOperatorName = telephonyManager.getSimOperatorName();

Upvotes: 12

pableu
pableu

Reputation: 3251

Never used it myself, but take a look at TelephonyManager->getNetworkOperatorName().

You could try something as simple as this:

TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String carrierName = manager.getNetworkOperatorName();

Upvotes: 148

fhucho
fhucho

Reputation: 34550

TelephonyManager telephonyManager = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
String operatorName = telephonyManager.getNetworkOperatorName();

Upvotes: 26

Related Questions