TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei_no=mngr.getDeviceId();
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
- it will work fine for IMEI Number of android phone but i needs
android Tablet PC SNID No.
Use this method it will return both fore mobile and tablet
public String getImeiNumber()
{
String imei;
final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null)
imei = mTelephony.getDeviceId(); // *** use for mobiles
else
imei = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); // *** use for
return imei;
}
Related
developed an app using a mobile phone
used this code to pick imei number
Utill.class
static TelephonyManager telephonyManager;
public static String getDeviceID(){
telephonyManager=(TelephonyManager) MyApplication.getInstance().getSystemService(MyApplication.getInstance().TELEPHONY_SERVICE);
return telephonyManager.getDeviceId();
}
in my job.class
String imeino = Util.getDeviceID();
tested with mobile devises and it works properly but when apk installed a tab (in client side ) imei number does not pick and give a null pointer
Note. for tab i have added different layouts and it also works properly in my tab
is this a matter of base url or
how can i avoid this issue of imei number ?
java Class and add following code
TelephonyManager tel;
TextView imei;
tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
imei = (TextView) findViewById(R.id.textView2);
imei.setText(tel.getDeviceId().toString());
AndroidManifest.xml and add following code
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Have this common method. Devices without SIM slot will return null IMEI. So pick ANDROID_ID.
public String getDeviceID(){
String devcieId;
TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null){
devcieId = mTelephony.getDeviceId();
}else{
devcieId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
}
return devcieId;
}
Try this code it will return you IMEI number if device GSM based or if not get back the Android ID.
String devcieId;
TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null){
devcieId = mTelephony.getDeviceId();
}else{
devcieId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
}
Also give the read phone state permission in your manifest.
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
This question already has answers here:
How to get the device's IMEI/ESN programmatically in android?
(22 answers)
Closed 8 years ago.
I want to get phone serial number by programming to registration configuration of my application and number of users and phones that my app has been installed on them.
Can I get that?
and can I get phone model that my app has been installed on them?
pls refer this
https://stackoverflow.com/a/1972404/951045
TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
mngr.getDeviceId();
add READ_PHONE_STATE permission to AndroidManifest.xml
public String getIMEI(Context context){
TelephonyManager mngr = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
String imei = mngr.getDeviceId();
return imei;
}
Here is the code:-
telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
deviceId = telephonyManager.getDeviceId();
Log.d(TAG, "getDeviceId() " + deviceId);
phoneType = telephonyManager.getPhoneType();
Log.d(TAG, "getPhoneType () " + phoneType);
try this
final TelephonyManager tm =(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
String deviceid = tm.getDeviceId();
Use below code for IMEI:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String imei= tm.getDeviceId();
How can I get The SIM card number using code ??
I tried this code and it returned no number
TelephonyManager tMgr =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
mPhoneNumber = tMgr.getLine1Number();
use
TelephonyManager phoneManager = (TelephonyManager)
getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = phoneManager.getLine1Number();
Needs READ_PHONE_STATE permission.
Try the following code:
TelephonyManager mTelephonyMgr =
(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String sDeviceID = mTelephonyMgr.getDeviceId();
String sSimSerial = mTelephonyMgr.getSimSerialNumber();
String sSimlineNumber = mTelephonyMgr.getLine1Number();
Set the following permission
android.permission.READ_PHONE_STATE in Android Manifest file
Try like this..
TelephonyManager telphMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String simSerialNumber = telphMgr.getSimSerialNumber();
Ref :
http://developer.android.com/reference/android/telephony/TelephonyManager.html#getSimSerialNumber%28%29
This is the following code to retrieve phone number wwas able to get it on samsung 4.0.4, but getting below error on htc one v mobile..any clue?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textDeviceID = (TextView)findViewById(R.id.deviceid);
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
textDeviceID.setText(getMy10DigitPhoneNumber(telephonyManager));
}
private String getMyPhoneNumber(){
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}
private String getMy10DigitPhoneNumber(TelephonyManager telephonyManager){
String s = getMyPhoneNumber();
return s.substring(0);
}
}
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String mblNumber = mTelephonyMgr.getLine1Number();
Note: Dont forget to add READ_PHONE_STATE permission to be added inside the AndroidManifest.xml file:
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
According to the documentation .getLine1Number() "Returns the phone number string for line 1, for example, the MSISDN for a GSM phone. Return null if it is unavailable. "
Apparently .getLine1Number() reads this information from SIM card, so if the operator has set the MSISDN field it will return you its value and null if they did not set this field.
In your case probably your SIM card does not have this field populated by operator.
I want to get the device id that will be unique for each Android device. I am presently developing for a Tablet device. Want to get unique device id and store the corresponding values...
So, i want to know whether Tablet devices will return a value if i use TelephonyManager.getDeviceId()...???Or is there any other value that is unique for each device???
TelephonyManger.getDeviceId() Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones.
final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String myAndroidDeviceId = mTelephony.getDeviceId();
But i recommend to use:
Settings.Secure.ANDROID_ID that returns the Android ID as an unique 64-bit hex string.
String myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
Sometimes TelephonyManger.getDeviceId() will return null, so to assure an unique id you will use this method:
public String getUniqueID(){
String myAndroidDeviceId = "";
TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null){
myAndroidDeviceId = mTelephony.getDeviceId();
}else{
myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
}
return myAndroidDeviceId;
}
This is not a duplicate question. As it turns out, Google's CTS require that getPhoneType of TelephonyManager needs to be none and getDeviceId of TelephonyManager needs to be null for non-phone devices.
So to get IMEI, please try to use:
String imei = SystemProperties.get("ro.gsm.imei")
Unfortunately, SystemProperties is a non-public class in the Android OS, which means it isn't publicly available to regular applications. Try looking at this post for help accessing it: Where is android.os.SystemProperties
Since Android 8 everything's changed. You should use Build.getSerial(), to get the serial number of the device and add the permission READ_PHONE_STATE.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
serial = Build.getSerial(); // Requires permission READ_PHONE_STATE
} else {
serial = Build.SERIAL; // Will return 'unknown' for device >= Build.VERSION_CODES.O
}
And get the IMEI or MEID this way:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String imei = tm.getImei(); // Requires permission READ_PHONE_STATE
serial = imei == null ? tm.getMeid() : imei; // Requires permission READ_PHONE_STATE
} else {
serial = tm.getDeviceId(); // Requires permission READ_PHONE_STATE
}