How do you get IMEI on a Verizon (CDMA vioice / LTE Data) device?

867 views Asked by At

getDeviceId() returns the 14 digit MEID on Verizon phones (because it is a CDMA voice device). Is there a programmatic way to get the 15 digit IMEI (as it is listed in the Settings menu) instead?

1

There are 1 answers

1
gsysko On BEST ANSWER

Disclaimer: Solution uses non-published APIs. This does not represent best practice and can cause unintended results. API may not be implemented or may change. Use at your own risk.

There is a way to do this with reflection and a hidden Android API call. TelephonyManager has a public (but hidden) method getImei(). Not ideal, but the following works for my particular need.

private String getIMEI() throws NoIMEIException {
    TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    try {
        Method method = mTelephonyMgr.getClass().getMethod("getImei");
        String imei = (String) method.invoke(mTelephonyMgr);
        if (imei == null) {
            throw new NoIMEIException();
        } else {
            return imei;
        }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        throw new NoIMEIException();
    }
}