How to find out carrier's name in Android

Android

Android Problem Overview


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

Android Solutions


Solution 1 - Android

Never used it myself, but take a look at http://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkOperatorName()">TelephonyManager->getNetworkOperatorName()</a>;.

You could try something as simple as this:

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

Solution 2 - Android

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

Solution 3 - Android

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();

Solution 4 - Android

A Kotlin null safe implementation:

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

Solution 5 - Android

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
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfhuchoView Question on Stackoverflow
Solution 1 - AndroidpableuView Answer on Stackoverflow
Solution 2 - AndroidfhuchoView Answer on Stackoverflow
Solution 3 - AndroidvelvalView Answer on Stackoverflow
Solution 4 - AndroidSir CodesalotView Answer on Stackoverflow
Solution 5 - AndroidKumar SantanuView Answer on Stackoverflow