Is IMEI available on all Android devices? Can it not be tampered?
This question already has an answer here:
I've been languishing on the internet to find an answer to the same problem. It appears getting something truly unique is very difficult.
1) Android_ID is returned either NULL or random shit 'with a major manufacturer` 2) telephonyManager.getDeviceId() is returned null with devices without sim card capabilities.
The best you can do is get IMEI number (.getDeviceId()) for devices where it is available and ANDROID_ID for devices when its not. You could at least, minimise your losses with having to roll out money only for devices without sim card facility which are rooted. Trust me, that's a very minor number.
References : This link should help.
Note : Too big to post as a comment.
Please refer this link:
http://android-developers.blogspot.in/2011/03/identifying-app-installations.html
There are various approaches suggested :
1:
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();
}
}
and i say use,
ANDROID_ID since it works pretty reliably for newer devices
链接地址: http://www.djcxy.com/p/24658.html上一篇: 活动在Android上重新启动