====== Eindeutige ID eines Android-Gerätes ======
**DEPRECATED** //Bitte alternative Methode weiter unten verwenden//\\
Um eine eindeutige ID eines Android-Gerätes zu ermitteln, kann folgendes Code-Snippet genutzt werden:
import java.util.UUID;
private static String getUniquePsuedoID() {
// If all else fails, if the user does have lower than API 9 (lower
// than Gingerbread), has reset their phone or 'Secure.ANDROID_ID'
// returns 'null', then simply the ID returned will be solely based
// off their Android device information. This is where the collisions
// can happen.
// Thanks http://www.pocketmagic.net/?p=1662!
// Try not to use DISPLAY, HOST or ID - these items could change.
// If there are collisions, there will be overlapping data
String m_szDevIDShort = "35" + (android.os.Build.BOARD.length() % 10) + (android.os.Build.BRAND.length() % 10) + (android.os.Build.CPU_ABI.length() % 10) + (android.os.Build.DEVICE.length() % 10) + (android.os.Build.MANUFACTURER.length() % 10) + (android.os.Build.MODEL.length() % 10) + (android.os.Build.PRODUCT.length() % 10);
// Thanks to @Roman SL!
// http://stackoverflow.com/a/4789483/950427
// Only devices with API >= 9 have android.os.Build.SERIAL
// http://developer.android.com/reference/android/os/Build.html#SERIAL
// If a user upgrades software or roots their phone, there will be a duplicate entry
String serial;
try {
serial = android.os.Build.class.getField("SERIAL").get(null).toString();
// Go ahead and return the serial for api => 9
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
} catch (Exception e) {
// String needs to be initialized
serial = "bewa"; // some value
}
// Thanks @Joe!
// http://stackoverflow.com/a/2853253/950427
// Finally, combine the values we have found by using the UUID class to create a unique identifier
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
}
Eine alternative Variante, welche die Android ID ausliest sieht so aus:
import android.provider.settings;
public class RequestHelper {
public static String getAndroidID(Context context) {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
}