它说“UUID可以在首次运行时生成,保存到文件中,然后随时检查以唯一标识安装。”
但是当我通过USB连接我的设备重新安装我的应用程序时,通过单击file.apk传输apk并将其安装在文件浏览器上。 UUID不会改变原因吗?
PlayStore更新或手动卸载和重新安装会改变吗?
编辑:存储UUID:
public 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();
}
}
从片段中抓住它:
idApplication = Installation.id(getActivity());