Thursday, 28 May 2015

Get SIM Serial number programmatically in android

Here I am going to explain how to get SIM Serial number programmatically in android

package com.example.get_mobilename;
import android.app.Activity;
import android.telephony.TelephonyManager;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TelephonyManager tel= (TelephonyManager)this.getSystemService(Context.
TELEPHONY_SERVICE); String SimSerialNumber = tel.getSimSerialNumber();
Toast.makeText(getApplicationContext(), SimSerialNumber,
Toast.LENGTH_LONG).show();
}

}







Add the below permission in your Manifestfile

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

Happy coding:)