title: Perfect unique_id for device except IMEI,Android_ID,WLAN Mac and Bluetooth address
body: <h2>Objective:</h2>
  
  <p>I am looking for a way to find out a <strong><em>unique_id</em></strong> for android device.</p>
  
  <h2>Background:</h2>
  
  <p>I will use the Id in login request payload and as my app is <strong><em>license based service app</em></strong> the Id should not change under normal circumstances. </p>
  
  <h2>Existing Approaches:</h2>
  
  <p>In iOS there are some <a href="http://www.doubleencore.com/2013/04/unique-identifiers/">unique id solutions for iOS</a> such as <strong><a href="https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFUUIDRef/index.html">CFUUID</a></strong> or <strong><em>identifierForVendor</em></strong> coupled with <strong><em>Keychain</em></strong>,Advertising Identifier etc..  that can do this job upto the expectation.</p>
  
  <p>But in Android all the options that I know seems to have hole in it.</p>
  
  <p><strong>IMEI:</strong></p>
  
  <pre><code>TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
  String m_deviceId = TelephonyMgr.getDeviceId();
  </code></pre>
  
  <p><strong>Drawbacks</strong></p>
  
  <p>It is sim card dependent so</p>
  
  <ul>
  <li><p>If there is no sim card then we're doomed</p></li>
  <li><p>If there is dual sim then we're dommed</p></li>
  </ul>
  
  <p><strong>Android_ID:</strong></p>
  
  <pre><code>  String m_androidId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
  </code></pre>
  
  <p><strong>Drawbacks</strong></p>
  
  <ul>
  <li>If OS version is upgraded then it may change</li>
  <li>If device is rooted it gets changed</li>
  <li>No guarantee that the device_id is unique there are some reports some manufacturers are having duplicate device_id</li>
  </ul>
  
  <p><strong>The WLAN MAC Address</strong></p>
  
  <pre><code>WifiManager m_wm = (WifiManager)getSystemService(Context.WIFI_SERVICE); 
  String m_wlanMacAdd = m_wm.getConnectionInfo().getMacAddress();
  </code></pre>
  
  <p><strong>Drawbacks</strong></p>
  
  <ul>
  <li>If there is no wifi hardware then we're doomed</li>
  <li>In some new devices If wifi is off then we're doomed.</li>
  </ul>
  
  <p><strong>Bluetooth Address:</strong></p>
  
  <pre><code>   BluetoothAdapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
     String m_bluetoothAdd = m_BluetoothAdapter.getAddress();
  </code></pre>
  
  <p><strong>Drawbacks:</strong></p>
  
  <ul>
  <li>if there is no bluetooth hardware we're doomed.</li>
  <li>In future in some new devices we mightn't able to read it if its off.</li>
  </ul>
  
  <h2>Possible solutions:</h2>
  
  <p>There are two approaches that I think to solve this problem</p>
  
  <ul>
  <li><p>We generate a random id by hashing timestamp with unique ids that I have mentioned and store it so next time during login we’ll check if the the stored value of key is null if its so then we’ll generate and store it else we’ll use the value of the key.</p>
  
  <p>If there is something equivalent to <strong><em>keychain</em></strong> of iOS then we’re good with this approach.</p></li>
  <li><p>Find a global identifier something like <strong><em>advertisingIdentifier</em></strong> of iOS which is same for all the apps in the device. </p></li>
  </ul>
  
  <p>Any help is appreciated !</p>