2016년 4월 26일 화요일

안드로이드 Unique ID 생성하기

public static String getDeviceUUID(final Context context) {
    final SharedPreferencesCache cache = Session.getAppCache();
    final String id = cache.getString(PROPERTY_DEVICE_ID);
 
    UUID uuid = null;
    if (id != null) {
        uuid = UUID.fromString(id);
    } else {
        final String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        try {
            if (!"9774d56d682e549c".equals(androidId)) {
                uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));
            } else {
                final String deviceId = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
                uuid = deviceId != null ? UUID.nameUUIDFromBytes(deviceId.getBytes("utf8")) : UUID.randomUUID();
            }
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
 
        Bundle bundle = new Bundle();
        bundle.putString(PROPERTY_DEVICE_ID, uuid.toString());
        cache.save(bundle);
    }
 
    return uuid.toString();
}

댓글 없음:

댓글 쓰기

언제까지의 개인정보처리방침

1. 개인정보의 처리 목적 언제까지 은(는) 다음의 목적을 위하여 개인정보를 처리하고 있으며, 다음의 목적 이외의 용도로는 이용하지 않습니다. - 고객 가입의사 확인, 고객에 대한 서비스 제공에 따른 본인 식별.인증, 회원자격 유지.관리, 물품 또는...