Android UDID like IPhone?

前端 未结 4 1005
猫巷女王i
猫巷女王i 2021-02-04 13:58

Does Android have a UDID like IPhone? If yes, is there a way I can get it programatically?

Thanks Chris

4条回答
  •  星月不相逢
    2021-02-04 15:02

    It's very easy to get the Android UDID - check out the following code:

    public class DemoActivityActivity extends Activity {
    
    /** Called when the activity is first created. */
    @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:

    
    

    For getting the Android ID you don't need to set any permission.

提交回复
热议问题