Sagar Agarwal
Sagar Agarwal

Reputation: 31

Android programming imei getDeviceID(telephonymanager)

How can I get IMEI number up to API level 19 (kitkat) in Android programming?

I have used getDeviceID(telephonyManager) but it is working only up to API 22 not below for API level 19.

Is there any other function that can be used?

Upvotes: 2

Views: 880

Answers (1)

Learning Always
Learning Always

Reputation: 1561

You may try this:

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
String IMEI_Number = telephonyManager.getDeviceId();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String Imei0Id = telephonyManager.getDeviceId(0); // hear 0 is slot number
        if (null != Imei0Id && !Imei0Id.equals("000000000000000")) {
            IMEI_Number = Imei0Id;
        }
    }

also check this link for good concept

https://developer.android.com/reference/android/telephony/TelephonyManager

on left side you found API Level Option that I mentioned in below picture by red mark. It will shows which are used by or not. enter image description here

Upvotes: 1

Related Questions