Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
How to Obtain the Connection Information Programmatically in Android?
Next article icon

How to Find Out Carrier's Name in Android Programmatically?

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article we will see how to retrieve the carrier name on Android device. This information can be useful for applications that need to provide specific functionality based on the user's cellular network provider. A sample video is given below to get an idea about what we are going to do in this article.

Step-by-Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.

Step 2: Adding Permissions

Navigate to app > manifests > AndroidMainfest.xml and add this

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

This permission declaration in Android manifest file specifies that the app requests permission to access the phone state which includes information about the device cellular network like carrier name.

Step 3: Creating Layout

We have created normal ui by adding one textview,one button and one Spinner for selecting the sim slot

activity_main4.xml:

XML
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:background="@color/white"     android:layout_height="match_parent"     android:gravity="center"     tools:context=".MainActivity4">      <androidx.cardview.widget.CardView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_margin="16dp"         app:cardCornerRadius="8dp">          <RelativeLayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:gravity="center"             android:padding="16dp">              <TextView                 android:id="@+id/tv"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="Hello World!"                 android:textSize="24sp" />              <Button                 android:id="@+id/btnSubmit"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_below="@id/tv"                 android:layout_marginTop="26dp"                 android:text="Submit" />              <Spinner                 android:id="@+id/spin"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_below="@id/btnSubmit"                 android:layout_marginTop="16dp" />          </RelativeLayout>      </androidx.cardview.widget.CardView>  </RelativeLayout> 

UI Output:

ui_carrier
activity_main4.xml

Step 4: Working on Kotlin File

Code retrieves and displays the carrier name for a selected SIM slot that is selected from a spinner after requesting the necessary permissions.

Kotlin
package com.ayush.gfgapp  import android.Manifest import android.content.Context import android.content.pm.PackageManager import android.os.Bundle import android.telephony.SubscriptionManager import android.widget.ArrayAdapter import android.widget.Button import android.widget.Spinner import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat  class MainActivity4 : AppCompatActivity() {     // Declaring UI elements     private lateinit var spin: Spinner     private lateinit var tv: TextView     private lateinit var btnSubmit: Button      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_main4)          // Initializing UI elements from our xml file         tv = findViewById(R.id.tv)         spin = findViewById(R.id.spin)         btnSubmit = findViewById(R.id.btnSubmit)          // Seting a click listener for the submit button         btnSubmit.setOnClickListener {             getCarrierName()         }          // Defining options for the Spinner         val slots = arrayOf("1", "2")          // Creating an ArrayAdapter for the Spinner         val _spinAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, slots)          // Seting the ArrayAdapter on the Spinner         spin.adapter = _spinAdapter          // Requesting permission to read phone state         ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_PHONE_STATE), PackageManager.PERMISSION_GRANTED)     }      private fun getCarrierName() {         // Geting the SubscriptionManager         val susbsManager = getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager          // Checking if the app has the required permission (that is Manifest.permission.READ_PHONE_STATE)         if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {             // If permission is not granted, display a message             tv.text = "Permission not granted"             return         }          // Retrieving the list of active subscriptions         val subsManagerList = susbsManager.activeSubscriptionInfoList          try {             // Geting the selected slot number from the Spinner             val selectedSlot = spin.selectedItem.toString().toInt()              // Retrieving information about the subscription in the selected slot             val subscriptionInfo = subsManagerList[selectedSlot - 1]              // Geting the carrier name or display "Unknown" if not available             val stringCarrierName = subscriptionInfo.carrierName?.toString() ?: "Unknown"              // Displaying the carrier name in text view             tv.text = stringCarrierName         } catch (e: Exception) {                tv.text = "Sim in slot ${spin.selectedItem.toString()} not available"         }     } } 

Output:


Next Article
How to Obtain the Connection Information Programmatically in Android?
author
ayu5hkarn
Improve
Article Tags :
  • Kotlin
  • Android
  • Geeks Premier League
  • Geeks Premier League 2023

Similar Reads

  • How to Get RAM Memory in Android Programmatically?
    RAM (Random Access Memory) of a device is a system that is used to store data or information for immediate use by any application that runs on the device. Every electronic device that runs a program as a part of its application has some amount of RAM associated with it. Mobile devices nowadays come
    3 min read
  • How to Find Dots-Per-Inch (DPI) of Screen in Android Programmatically?
    Dots-Per-Inch or DPI is a measure of pixel density over the physical area on the screen. A pixel is the smallest unit of any screen display. and the sum of all the pixels present on the screen is termed as Screen Resolution. The pixels available to the user are called Viewport and in this article, w
    2 min read
  • How to Fetch Device ID in Android Programmatically?
    The android Device ID is a unique code, string combinations of alphabets and numbers, given to every manufactured android device. This code is used to identify and track each android device present in the world. In Android, the Device ID is typically related to the Google Play Services and is most c
    3 min read
  • How to Obtain the Connection Information Programmatically in Android?
    Sometimes it becomes challenging to find the network-related details, especially the device's IP address, which could be needed to grant unique preferences through the modem software. Because of the variance in the information shown to the user across multiple Android devices (Samsung, Mi, Lava), we
    4 min read
  • How to Check GPS is On or Off in Android Programmatically?
    GPS (Global Positioning System) is a satellite-based navigation system that accommodates radio signals between satellite and device to process the device's location in the form of coordinates. GPS gives latitude and longitude values of the device. Recent mobile phones are equipped with GPS modules t
    3 min read
  • How to Check Airplane Mode State in Android Programmatically?
    Airplane Mode is often seen in action during flights, avoiding calls, or rebooting the network on mobiles, tablets, and laptops. Airplane mode is a standalone mode where the device turns down the radio communications. These may include Wifi, GPS, Telephone Network, Hotspot depending upon the year of
    3 min read
  • How to Programmatically Enable/Disable Wi-Fi in Android?
    In Android Phone, it is very much easy to enable/disable WiFi by using the WiFi icon, but have you wondered how to do this task programmatically in Android. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project usin
    3 min read
  • How to Set Background Drawable Programmatically in Android?
    In many android applications, we can get to see that the background color of this application changes dynamically when updated from the server. For updating this color we have to set the background color of our layout programmatically. In this article, we will take a look at How to Set Background Dr
    3 min read
  • How to Get the Device's IMEI and ESN Programmatically in Android?
    Many times while building Android Applications we require a unique identifier to identify the specific mobile users. For identifying that user we use a unique address or identity. For generating that unique identity we can use the android device id. In this article, we will take a look at How to get
    4 min read
  • How to Get the MAC of an Android Device Programmatically?
    MAC stands for Media Access Control. The MAC address is also known as the Equipment Id Number. This MAC Address is provided by the Network Interface Card. In this article, we will see step by step from creating a new empty project to How to make an android app to display MAC Address using Java. Note
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences