Here is the Simple Statement to find Android Device ID which return a String.
String udid = Secure.getString(getContentResolver(), Secure.ANDROID_ID)
Please Note :
we had seen only how to get ANDROID_D.
Now We will see the Difference Between Android ID & Device ID of Android Phone
Android ID :
Here is sample Code to get UDID
public class DemoActivity 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("ID", "Android ID: " + Secure.getString(getContentResolver(), Secure.ANDROID_ID));
Log.d("ID", "Device ID : " + tm.getDeviceId());
}
}
For getting Device ID you have to set following permission in AndroidMenifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
For getting ANDROID_ID you don't need to set any permission.
ANDROID_ID seems a good choice for a unique device identifier.
String udid = Secure.getString(getContentResolver(), Secure.ANDROID_ID)
Please Note :
ANDROID_ID is a 64-bit number (as a hex string) that is RANDOMLY GENERATED on the device's first boot and should remain constant for the lifetime of the device.(The value may change if a factory reset is performed on the device.)
we had seen only how to get ANDROID_D.
Now We will see the Difference Between Android ID & Device ID of Android Phone
Android ID :
ANDROID_ID is a 64-bit number (as a hex string) that is RANDOMLY GENERATED on the device's first boot and should remain constant for the lifetime of the device.(The value may change if a factory reset is performed on the device.)Device ID :
Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones.
Here is sample Code to get UDID
public class DemoActivity 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("ID", "Android ID: " + Secure.getString(getContentResolver(), Secure.ANDROID_ID));
Log.d("ID", "Device ID : " + tm.getDeviceId());
}
}
For getting Device ID you have to set following permission in AndroidMenifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
For getting ANDROID_ID you don't need to set any permission.
ANDROID_ID seems a good choice for a unique device identifier.
Comments
Post a Comment