123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package com.edufound.mobile.util;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.provider.Settings;
- import android.telephony.TelephonyManager;
- import java.io.UnsupportedEncodingException;
- import java.util.UUID;
- public class DeviceUuidFactory {
- public static final String UUID_SPKEY = "uuid";
- protected static UUID uuid;
- public DeviceUuidFactory(Context context) {
- if (uuid == null) {
- synchronized (DeviceUuidFactory.class) {
- if (uuid == null) {
- try {
- final String androidId = Settings.Secure.getString(
- context.getContentResolver(), Settings.Secure.ANDROID_ID);
- if (!"9774d56d682e549c".equals(androidId)) {
- uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));
- } else {
- @SuppressLint("MissingPermission") final String deviceId = ((TelephonyManager) context
- .getSystemService(Context.TELEPHONY_SERVICE))
- .getDeviceId();
- uuid = deviceId != null ? UUID.nameUUIDFromBytes(deviceId
- .getBytes("utf8")) : UUID.randomUUID();
- try {
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
- SPutil.setPrefString(context, UUID_SPKEY, uuid.toString());
- }
- }
- }
- /**
- * @return UUID
- */
- public static UUID getUuid() {
- if (uuid == null || uuid.equals("") || uuid.equals("null")) {
- return null;
- }
- return uuid;
- }
- }
|