0

Good Day! I am working on an android app which monitor mobile name and model. I am using TELEPHONY SERVICE but i am in trouble how to write code for get mobile IMEI number.

Aqi Khan
  • 13
  • 1
  • duplicated question http://stackoverflow.com/questions/14660938/how-can-i-get-phone-serial-number-imei – spacebiker Oct 15 '14 at 12:48
  • possible duplicate of [How to programmatically get the devices IMEI/ESN in Android](http://stackoverflow.com/questions/1972381/how-to-programmatically-get-the-devices-imei-esn-in-android) – Batuhan Coşkun Oct 15 '14 at 13:41

3 Answers3

1
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 // get IMEI
String imei = tm.getDeviceId();
String phone = tm.getLine1Number();

but its not always reliable on for example non phone device. You will also need to add permision "android.permission.READ_PHONE_STATE".

TelephonyManager

Google Doc

Community
  • 1
  • 1
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28
1

You can use this:

String deviceModel = Build.MODEL;
String deviceBrand = Build.BRAND;
TelephonyManager manager = getSystemService(Context.TELEPHONY_SERVICE); 
String imei = manager.getDeviceId();

Also add that permission to your manifest.

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

If you want to get another info about your phone, you should read the links;

Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48
0
  public String getDeviceName() 
   {
    String manufacturer = Build.MANUFACTURER;
    String model = Build.MODEL;
    if (model.toLowerCase().startsWith(manufacturer.toLowerCase())) {
        return capitalize(model);
    } 
    else {
        return capitalize(manufacturer) + " " + model;
    }
}




private String capitalize(String s) {
    if (s == null || s.length() == 0) {
        return "";
    }
    char first = s.charAt(0);
    if (Character.isUpperCase(first)) 
     {
        return s;
    } else {
        return Character.toUpperCase(first) + s.substring(1);
    }
} 
Afroz Ahmad
  • 69
  • 10