How can I get the UUID of my Android phone in an application?

后端 未结 7 2273
野趣味
野趣味 2020-11-27 10:58

I\'m looking for help to get the UUID of my Android phone. I have searched the net and found one potential solution but it is not working in the emulator.

Here is th

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 11:36

    Add

      
    

    Method

    String getUUID(){
        TelephonyManager teleManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        String tmSerial = teleManager.getSimSerialNumber();
        String tmDeviceId = teleManager.getDeviceId();
        String androidId = android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
        if (tmSerial  == null) tmSerial   = "1";
        if (tmDeviceId== null) tmDeviceId = "1";
        if (androidId == null) androidId  = "1";
        UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDeviceId.hashCode() << 32) | tmSerial.hashCode());
        String uniqueId = deviceUuid.toString();
        return uniqueId;
    }
    

提交回复
热议问题