TelephonyManager.getDeviceId仅返回14位数

时间:2012-01-11 21:13:01

标签: android

TelephonyManager.getDeiceId()仅返回14位IMEI号码。 但在Setting-> Phone-> Status下显示15位数字。

我希望手机设置下显示15位数字。

4 个答案:

答案 0 :(得分:3)

IMEI(14位)由校验位补充。校验位不是 在IMEI检查时发送的部分数字。校验位应该 避免手动传输错误,例如当客户注册被盗手机时 在运营商的客户服务台。

http://www.tele-servizi.com/Janus/texts/imei.txt

http://en.wikipedia.org/wiki/International_Mobile_Equipment_Identity

答案 1 :(得分:1)


TelephonyManager mTelephonyMgr;
 mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
 mTelephonyMgr.getDeviceId()

这就是我所做的,我得到了所有15位数字,这可以帮助你......

答案 2 :(得分:1)

或者您可以手动计算14位IMEI号的校验和。 e.g。

private int GetCheckSumDigit(String id) {
        int digit = -1;
        try{
            if(id.length() == 14)
            {
                String str = "";
                char[] digits = new char[id.length()];
                id.getChars(0, id.length(), digits, 0);
                for(int i=0; i<digits.length; i++)
                {
                    String ch = digits[i]+"";
                    if((i+1)%2==0)
                    {
                        int x = Integer.parseInt(digits[i]+"");
                        x *= 2;
                        ch = x+"";
                    }
                    str += ch;
                }
                digits = new char[str.length()];
                str.getChars(0, str.length(), digits, 0);
                int total = 0;
                for(int i=0; i<str.length(); i++)
                    total += Integer.parseInt(digits[i]+"");
                //
                int count = 0;
                while((total+count)%10 != 0)
                    count++;
                digit = count;
            }
        }catch(Exception exx)
        {
            exx.printStackTrace();
        }
        return digit;
    }

祝你好运。

答案 3 :(得分:0)

有些设备不会添加最后一位数字,我们需要使用Luhn algorithm计算最后一位数字:

private int getImeiCheckDigit(String imei14digits) {
    if (imei14digits == null || imei14digits.length() != 14) {
        throw new IllegalArgumentException("IMEI should be 14 digits");
    }
    int[] imeiArray = new int[imei14digits.length()];
    final int DIVIDER = 10;
    char[] chars = imei14digits.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        imeiArray[i] = Character.getNumericValue(chars[i]);
    }
    int sum = 0;
    for (int i = 0; i < imeiArray.length; i++) {
        if (i % 2 == 0) {
            sum += imeiArray[i];
        } else {
            int multi = imeiArray[i] * 2;
            if (multi >= DIVIDER) {
                sum += multi % DIVIDER;
                sum += multi / DIVIDER;
            } else {
                sum += multi;
            }
        }
    }
    return (DIVIDER - sum % DIVIDER) % DIVIDER;
}
相关问题