{"id":3173,"date":"2017-04-01T15:31:51","date_gmt":"2017-04-01T10:01:51","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=3173"},"modified":"2017-04-01T15:31:51","modified_gmt":"2017-04-01T10:01:51","slug":"unique-android-device-id","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/unique-android-device-id\/","title":{"rendered":"Is there a unique Android device ID"},"content":{"rendered":"<h4 id=\"device-id\"><span style=\"color: #ff6600;\"><b>Device ID:<\/b><\/span><\/h4>\n<ul>\n<li>A\u00a0<b>device ID<\/b>\u00a0(<b>device<\/b>\u00a0identification) is a distinctive number associated with a smartphone or similar handheld\u00a0<b>device<\/b>.<\/li>\n<li><b>Device<\/b>\u00a0IDs are separate from hardware serial numbers.<\/li>\n<\/ul>\n<p><span style=\"color: #808000;\"><b>How do find my android device ID?<\/b><\/span><\/p>\n<ol>\n<li>Dial *#06#. The number should display on our screen.<\/li>\n<li>The IMEI \/ IMSI \/ MEID is displayed in the device&#8217;s phone status setting.<\/li>\n<li>The ID may be under or below the battery or on the back or bottom of the device.<\/li>\n<li>Use the number &#8220;0&#8221; instead of the letter &#8220;o&#8221;. Close.<\/li>\n<\/ol>\n<h4 id=\"android-id\"><span style=\"color: #800080;\"><b>Android ID:<\/b><\/span><\/h4>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">java code<\/span> <\/div> <pre class=\"language-java code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-java code-embed-code\">String androidID = Settings.Secure.getString(MainActivity.this.getContentResolver(),<br\/>            Settings.Secure.ANDROID_ID);<\/code><\/pre> <\/div>\n<h4 id=\"device-id-2\"><span style=\"color: #ff6600;\"><b>Device ID:<\/b><\/span><\/h4>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">java code<\/span> <\/div> <pre class=\"language-java code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-java code-embed-code\">String deviceID = ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE))<br\/>                    .getDeviceId()<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<ul>\n<li>DeviceID: This is the serial of the device, which should persist even a factory reset.<\/li>\n<li>AndroidID: This will be set at the first boot (either with a brand new device, or after a factory reset). As implicated, it does not survive a factory-reset<\/li>\n<li>There&#8217;s a second &#8220;Android_ID&#8221; which is generated and used by the Google Services Framework (GSF), and thus often referenced as &#8220;GSF ID&#8221;. Behaves basically like the AndroidID mentioned before (e.g. doesn&#8217;t survive a factory-reset), and co-exists with it.<\/li>\n<li>Furthermore, there&#8217;s the GAID (Google Advertising ID), which can be reset by the user via the Google Settings app.<\/li>\n<li>During &#8220;normal operation&#8221; (i.e. as long as you not factory-reset your device or reset the GAID), all these IDs can be used to identify the device. When using multiple users (via user profiles) on a device, all except the DeviceID would even identify the user (profile).<\/li>\n<\/ul>\n[ad type=&#8221;banner&#8221;]\n<h4 id=\"tenets-of-working-with-android-identifiers\"><span style=\"color: #808000;\"><b>Tenets of Working with Android Identifiers<\/b><\/span><\/h4>\n<p><b>#: Avoid using hardware identifiers.<\/b>\u00a0Hardware identifiers such as SSAID (Android ID) and IMEI can be avoided in most use-cases without limiting required functionality.<\/p>\n<p><b>#: Only use Advertising ID for user profiling or ads use-cases.<\/b>\u00a0When using an\u00a0Advertising ID<u>, <\/u>always respect the\u00a0Limit Ad Tracking\u00a0flag, ensure the identifier cannot be connected to personally identifiable information (PII) and avoid bridging Advertising ID resets.<\/p>\n<p><b><i>#: Use an Instance ID or a privately stored GUID whenever possible for all other use-cases except payment fraud prevention and telephony.<\/i><\/b>\u00a0For the vast majority of non-ads use-cases, an instance ID or GUID should be sufficient.<\/p>\n<p><b><i>#: Use APIs that are appropriate to your use-case to minimize privacy risk.<\/i><\/b>\u00a0Use the\u00a0DRM API\u00a0API for high value content protection and the\u00a0SafetyNet API\u00a0for abuse prevention. The Safetynet API is the easiest way to determine whether a device is genuine without incurring privacy risk.<\/p>\n<p><b>Settings.Secure#ANDROID_ID<\/b> returns the Android ID as an unique for each user 64-bit hex string.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">java code<\/span> <\/div> <pre class=\"language-java code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-java code-embed-code\">import android.provider.Settings.Secure;<br\/><br\/>private String android_id = Secure.getString(getContext().getContentResolver(),<br\/>                                                        Secure.ANDROID_ID); <\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<ul>\n<li>All devices tested returned a value for TelephonyManager.getDeviceId()<\/li>\n<li>All GSM devices (all tested with a SIM) returned a value for TelephonyManager.getSimSerialNumber()<\/li>\n<li>All CDMA devices returned null for getSimSerialNumber() (as expected)<\/li>\n<li>All devices with a Google account added returned a value for ANDROID_ID<\/li>\n<li>All CDMA devices returned the same value (or derivation of the same value) for both ANDROID_ID and TelephonyManager.getDeviceId() &#8212; as long as a Google account has been added during setup.<\/li>\n<\/ul>\n<p>So if you want something unique to the device itself, TM.getDeviceId() should be sufficient. Obviously some users are more paranoid than others, so it might be useful to hash 1 or more of these identifiers, so that the string is still virtually unique to the device, but does not explicitly identify the user&#8217;s actual device. For example, using String.hashCode(), combined with a UUID:<\/p>\n<p>Read the TelephonyManager properties, so add this to your manifest:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">java code<\/span> <\/div> <pre class=\"language-java code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-java code-embed-code\">&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; \/&gt;<\/code><\/pre> <\/div>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">java code<\/span> <\/div> <pre class=\"language-java code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-java code-embed-code\">final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE); <br\/>final String tmDevice, tmSerial, androidId; <br\/>tmDevice = &quot;&quot; + tm.getDeviceId(); tmSerial = &quot;&quot; + tm.getSimSerialNumber(); <br\/>androidId = &quot;&quot; + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); <br\/>UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() &lt;&lt; 32) | tmSerial.hashCode()); <br\/>String deviceId = deviceUuid.toString(); <\/code><\/pre> <\/div>\n<h4 id=\"import-libs\"><span style=\"color: #800080;\"><strong>import libs<\/strong><\/span><\/h4>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">java code<\/span> <\/div> <pre class=\"language-java code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-java code-embed-code\">import android.content.Context;<br\/>import android.telephony.TelephonyManager;<br\/>import android.view.View;<\/code><\/pre> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Device ID: A\u00a0device ID\u00a0(device\u00a0identification) is a distinctive number associated with a smartphone or similar handheld\u00a0device. Device\u00a0IDs are separate from hardware serial numbers. How do find my android device ID? Dial *#06#. The number should display on our screen. The IMEI \/ IMSI \/ MEID is displayed in the device&#8217;s phone status setting. The ID may [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1791],"tags":[5911,5917,5915,5914,5910,5909,5916,5922,5908,5920,5921,5919,5923,5918,5912,5913,2177],"class_list":["post-3173","post","type-post","status-publish","format-standard","hentry","category-android","tag-android-device-id-example","tag-android-error-failed-to-install-apk-on-device-timeout","tag-android-get-device-id-for-push-notifications","tag-android-get-device-imei","tag-android-get-device-uuid","tag-android-instance-id","tag-android-unique-device-id-from-native-code","tag-can-i-use-the-serial-number-to-uniquely-identify-android-device-api-9","tag-how-to-get-device-id-in-android-programmatically","tag-how-to-send-this-android-device-id-to-database-using-json","tag-if-unique-id-of-android-device-changed-what-is-the-unchanged","tag-is-there-a-way-to-identify-every-android-device-as-a-unique-device","tag-mobile-device-uniqueness-for-ios-and-android","tag-proper-use-cases-for-android-usermanager-isuseragoat","tag-using-getstring-to-get-device-identifiers-is-not-recommended","tag-what-is-android-id","tag-why-is-it-faster-to-process-a-sorted-array-than-an-unsorted-array"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/3173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=3173"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/3173\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=3173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=3173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=3173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}