TelephonyManager.getDeviceId() 가 참 유용하기는 한데, 핸드폰에서만 되지 태블릿이나 웨어러블 기기에서는 null 값을 넘긴다고 합니다.
그러면 도대체 어떻게 디바이스를 정확하게 구분할 수 있을까요? 여러 자료들을 찾아보던 중, 카톡 SDK 에 다음 함수가 있음을 알 수 있었습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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) 안드로이드 개별 디바이스를 번역하는 방법 (안드로이드 공식 블로그의 번역) http://huewu.blog.me/110107222113
(참고자료 2) IMEI, MEID, ESN, IMSI 등에 대해 자세히 나옴 http://www.webs.co.kr/index.php?mid=adnroid&sort_index=readed_count&order_type=asc&page=2&document_srl=38470
(참고자료 3) Stack Overflow 의 방대한 문답들 http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id
(참고자료 4) 카카오톡 안드로이드 SDK https://developers.kakao.com/docs/android
Designed by sketchbooks.co.kr / sketchbook5 board skin
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5