2

I need to validate IMEI number, is their any mechanism for validating the input IMEI? Can we get status of validation in true or false ?

sarjeet singh
  • 461
  • 4
  • 10
  • 2
    Why do you need to validate an IMEI number? If you're an enterprise app doing some form of tracking, you're probably the device owner and in that case you can get it. If you aren't, there's no good reason for you to need to know the IMEI. This was removed on purpose, to prevent tracking at the hardware level. – Gabe Sechan Jun 17 '22 at 17:24
  • We are running a use case where we are giving phones to employees of an organization, like a laptop being issued to users. We have record of which IMEI was issued to which user, now we need to validate if the App has been downloaded on the same phone. So we are not asking what is the IMEI number - only asking if the one we have is the right one. – sarjeet singh Jun 20 '22 at 06:12
  • 3
    That's a case for for enrolling it in enterprise device management, not writing an app that needs the IMEI. See https://www.android.com/enterprise/management/ That also allows you to control what is installed on the device, security updates, etc. – Gabe Sechan Jun 20 '22 at 19:41

2 Answers2

4

You cannot, Third-party apps can not use IMEI nor the serial number of a phone and other non-resettable device identifiers.

Restriction on non-resettable device identifiers

Starting in Android10, apps must have the READ_PRIVILEGED_PHONE_STATE privileged permission in order to access the device's non-resettable identifiers, which include both IMEI and serial number. read more

You can still get the non-resettable device identifiers in older android versions by calling android.telephony.TelephonyManager.getDeviceId().

Alternatively, If you can get a unique id use this code

Secure.getString(getContext().getContentResolver(),Secure.ANDROID_ID);
Sidharth Mudgil
  • 1,293
  • 8
  • 25
0

No, you cannot get IMEI after Android 10, Use This Approach will do the same purpose, but beware it's not the same for debugging and release also it contains both Numbers and Letters.

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
     imei = Settings.Secure.getString(Objects.requireNonNull(getContext()).getContentResolver(), Settings.Secure.ANDROID_ID);
    }
Islam Alshnawey
  • 692
  • 10
  • 15
  • Useful, but not quite the same purpose. [Settings.Secure.ANDROID_ID](https://developer.android.com/reference/android/provider/Settings.Secure): *"... unique to each **combination of app-signing key, user, and device**"*. It does not identify the device; though it does allow app to distinguish between downloads to different devices. The benefit it has over something you could do yourself when app first starts (create and save a GUID), is that it (hopefully) persists if the app is deleted then reinstalled. Not sure that is guaranteed across Android OS updates, if app is deleted during update. – ToolmakerSteve Jan 12 '23 at 03:54