Thursday, May 29, 2014

UDID equivalent of iPhone in Android

It's very easy to get the Android UDID - check out the following code:
public class DemoActivityActivity extends Activity {
@Override public void onCreate(Bundle savedInstanceState) {  
super.onCreate(savedInstanceState);  
setContentView(R.layout.main);
    TelephonyManager tm = (TelephonyManager)  
this.getSystemService(Context.TELEPHONY_SERVICE);
    Log.d(">>>>", "Android ID: " +Secure.getString(getContentResolver(), Secure.ANDROID_ID));
        Log.d(">>>>", "Device ID : " + tm.getDeviceId());
       }
}
For getting the Device ID you have to set following permission in AndroidManifest.xml:
 <android:name="android.permission.READ_PHONE_STATE"/>
For getting the Android ID you don't need to set any permission.

Attribution:
http://stackoverflow.com/a/10085178/730807

No comments:

Post a Comment