Open top menu


In this tutorial we will explain how to get Sim Card Details for Example- Sim Serial Number, Sim Card Number, Sim Country code, Sim Card Operator Name, Sim Card Code etc.



First you can add READ_PHONE_STATE permission in android manifest file.

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


activity_main.xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:tools="http://schemas.android.com/tools"    
android:id="@+id/activity_main"    
android:layout_width="match_parent"    
android:layout_height="match_parent"    
android:orientation="vertical"    
android:gravity="center|top">

    
<TextView        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Android Beginner Point Tutorials"        
android:textSize="18dp"       
 android:visibility="invisible"        
android:textStyle="bold"       
 android:textColor="#066001"        />

    
<Button        
android:text="Get Sim Detail"       
 android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:id="@+id/button"        />

   
 <TextView        
android:text="TextView"       
 android:layout_width="match_parent"        
android:layout_height="wrap_content"        
android:id="@+id/textView"        
android:gravity="center_vertical"        
android:textStyle="bold"        
android:textSize="18dp"        
android:layout_margin="30dp"/>

</LinearLayout>


MainActivity.java

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    Button btnDetail;
    TextView text;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnDetail=(Button)findViewById(R.id.button);
        btnDetail.setOnClickListener(this);
        text=(TextView)findViewById(R.id.textView);
    }

    @Override    public void onClick(View v) {
        TelephonyManager telephonyManager = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
        int simState = telephonyManager.getSimState();
        switch (simState) {
            case (TelephonyManager.SIM_STATE_ABSENT): break;
            case (TelephonyManager.SIM_STATE_NETWORK_LOCKED): break;
            case (TelephonyManager.SIM_STATE_PIN_REQUIRED): break;
            case (TelephonyManager.SIM_STATE_PUK_REQUIRED): break;
            case (TelephonyManager.SIM_STATE_UNKNOWN): break;
            case (TelephonyManager.SIM_STATE_READY): {

                // Get SIM country ISO code.................                
String Country = telephonyManager.getSimCountryIso();
                // Get operator code of the active SIM (MCC + MNC)                
String OperatorCode = telephonyManager.getSimOperator();
                // Get name of the SIM operator...............               
 String OperatorName = telephonyManager.getSimOperatorName();
                // Get SIM’s serial number.....................                
String Serial = telephonyManager.getSimSerialNumber();
                // Get Contact Number...........................               
 String Number = telephonyManager.getLine1Number();
                // Display All Sim Information..................                
text.setText("CountryIso :-"+Country+"\n\n"+"OperatorCode :-"                        
+OperatorCode+"\n\n" +"OperatorName :-"+OperatorName+"\n\n"                       
 +"Serial :-"+Serial+"\n\n"+"PhoneNumber :-"+Number);
            }
        }
    }
}






0 comments