0

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 ?

OBX
  • 6,044
  • 7
  • 33
  • 77
Sisara Ranasinghe
  • 131
  • 1
  • 2
  • 11

3 Answers3

3

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"/>
Android
  • 535
  • 5
  • 16
2

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;
    }
Dhinakaran Thennarasu
  • 3,336
  • 4
  • 26
  • 39
0

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"/>
Ahsan Kamal
  • 1,085
  • 2
  • 13
  • 34