Created
July 20, 2016 17:53
-
-
Save LuizGadao/90f402ba8df3430c7581d7b3645bcb49 to your computer and use it in GitHub Desktop.
Android get telephone IMSI code. Add permission "android.permission.READ_PHONE_STATE"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.luizgadao.pocimsi; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.telephony.TelephonyManager; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
TextView tvImsi = (TextView) findViewById(R.id.tvImsi); | |
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE); | |
try{ | |
String imsi = telephonyManager.getSubscriberId(); | |
if (imsi != null) | |
tvImsi.setText("IMSI: " + telephonyManager.getSubscriberId()); | |
}catch (Exception e){ | |
e.printStackTrace(); | |
tvImsi.setText("this device not have GCM-SIM"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment