Android getSerial() 未返回实际序列号或 IMEI

Android getSerial() not returning the actual serial number or IMEI

我想我已经开始工作了,但是来自 getSerial() 请求的数据不准确。

结果与我设备的 "about" 部分中的任何内容都不匹配。

我需要此信息来帮助我的最终用户致电我们的帮助台 - 他们需要通过序列号识别他们的设备

有没有办法将 getSerial() 转换为实际的序列号?

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

String serialNumber;
serialNumber = android.os.Build.getSerial();

有人知道如何获取实际信息吗?

TelephonyManager tManager = (TelephonyManager)myActivity.getSystemService(Context.TELEPHONY_SERVICE);
String uid = tManager.getDeviceId();

getSystemService 是 Activity class 中的一个方法。 getDeviceID() 将 return 设备的 MDN 或 MEID,具体取决于 phone 使用的无线电(GSM 或 CDMA)。

每个设备必须 return 此处有一个唯一值(假设它是 phone)。这应该适用于任何带有 sim 插槽或 CDMA 收音机的 Android 设备。您只能靠 Android 供电的微波炉 ;-)

事实证明,获得唯一的硬件标识符越来越难,因此最好围绕无法访问这些类型的信息来规划应用程序,而是创建您自己的。

我阅读了很多文章并测试了很多代码示例,最终偶然发现了这个 gem 并且发现它非常有用:

创建一个 Class 名为安装:

public static class Installation {
    private static String sID = null;
    private static final String INSTALLATION = "INSTALLATION";

    public synchronized static String id(Context context) {
        if (sID == null) {
            File installation = new File(context.getFilesDir(), INSTALLATION);
            try {
                if (!installation.exists())
                    writeInstallationFile(installation);
                sID = readInstallationFile(installation);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return sID;
    }

    private static String readInstallationFile(File installation) throws IOException {
        RandomAccessFile f = new RandomAccessFile(installation, "r");
        byte[] bytes = new byte[(int) f.length()];
        f.readFully(bytes);
        f.close();
        return new String(bytes);
    }

    private static void writeInstallationFile(File installation) throws IOException {
        FileOutputStream out = new FileOutputStream(installation);
        String id = UUID.randomUUID().toString();
        out.write(id.getBytes());
        out.close();
    }
}

您应用程序中任何需要该唯一 ID 的地方 - 只需调用它来获取它 - 或者第一次创建它:

    //INSTALLATION ID
    String installID =  Installation.id(this);
    Log.w("INSTALLATION_ID", installID);

超级简单 如果您需要或想要将您的应用程序安装所特有的任何其他内容保存到同一个位置,并且可以扩展。