我正在实施Google的许可系统,对于混淆器,我需要生成一个唯一的ID。该文件说

/**
 * @param salt an array of random bytes to use for each (un)obfuscation
 * @param applicationId application identifier, e.g. the package name
 * @param deviceId device identifier. Use as many sources as possible to
 *    create this unique identifier.
 */
public AESObfuscator(byte[] salt, String applicationId, String deviceId) {


除了通过获取的软件包名称和设备ID

private String android_id = Secure.getString(getContext().getContentResolver(),
                                                    Secure.ANDROID_ID);


我还能使用哪些其他来源?

谢谢

最佳答案

Secure.ANDROID_ID有时为空,我相信可以在有根电话上对其进行更改,因此您应该考虑检查其他一些选项,例如TelephonyManager.getDeviceId()

我在this question上找到的一个不错的代码片段执行以下操作以生成唯一ID:

final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, androidId;

tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
String deviceId = deviceUuid.toString();

09-27 01:53
查看更多