我怎样才能获得Android设备的唯一ID? [英] How can I get android device Unique ID?

查看:157
本文介绍了我怎样才能获得Android设备的唯一ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  是否有独特的Andr​​oid设备ID?


我用低于code获得Android设备的IMEI和如何更改低于code获得Android设备的唯一ID。

 字符串getDeviceID1(TelephonyManager phonyManager){
    字符串ID = phonyManager.getDeviceId();
    如果(ID == NULL){
        ID =不可用;
    }
    INT PHONETYPE = phonyManager.getPhoneType();
    开关(PHONETYPE){
        案例TelephonyManager.PHONE_TYPE_NONE:
            返回+身份证;        案例TelephonyManager.PHONE_TYPE_GSM:
            返回+身份证;        案例TelephonyManager.PHONE_TYPE_CDMA:
            返回+身份证;        / *
        *对于API等级11以上
        *案例TelephonyManager.PHONE_TYPE_SIP:
        *回报SIP;
        * /        默认:
            返回+身份证;
    }    //我用来显示IMEI    TextView的textDeviceID =(的TextView)findViewById(R.id.deviceid);
    //检索到TelephonyManager的一个实例的引用
    TelephonyManager telephonyManager =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    textDeviceID.setText(getDeviceID1(telephonyManager));
}


解决方案

在Android中,你可以得到三种不同的唯一的ID。


  • IMEI(你在你的code已经有了)

      TelephonyManager telephonyManager =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    字符串ID =(getDeviceID1(telephonyManager));


  • 设备ID

     字符串android_id = Secure.getString(的getContext()。getContentResolver()
                                                    Secure.ANDROID_ID);


  • 蓝牙地址(这也将是唯一的每个设备)

     私人BluetoothAdapter mBtAdapter;//获取本地蓝牙适配器
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    串deviceMacAddress = mBtAdapter.getAddress();


Possible Duplicate:
Is there a unique Android device ID?

I used below code to get android device IMEI and How can I change below code to get android device Unique ID.

String getDeviceID1(TelephonyManager phonyManager){
    String id = phonyManager.getDeviceId();
    if (id == null){
        id = "not available";
    }
    int phoneType = phonyManager.getPhoneType();
    switch(phoneType){
        case TelephonyManager.PHONE_TYPE_NONE:
            return "" + id;

        case TelephonyManager.PHONE_TYPE_GSM:
            return "" + id;

        case TelephonyManager.PHONE_TYPE_CDMA:
            return "" + id;

        /*
        *  for API Level 11 or above
        *  case TelephonyManager.PHONE_TYPE_SIP:
        *   return "SIP";
        */

        default:
            return "" + id;
    }

    //I used to show IMEI 

    TextView textDeviceID = (TextView)findViewById(R.id.deviceid);
    //retrieve a reference to an instance of TelephonyManager
    TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    textDeviceID.setText(getDeviceID1(telephonyManager));
}

解决方案

In Android, you can get three different Unique Ids.

  • IMEI ( which you have in your code already )

    TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String id =  (getDeviceID1(telephonyManager));
    

  • Device ID

    String android_id = Secure.getString(getContext().getContentResolver(),
                                                    Secure.ANDROID_ID); 
    

  • Bluetooth Address ( this will also be unique for each device )

    private BluetoothAdapter mBtAdapter;
    
    // Get the local Bluetooth adapter
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    String deviceMacAddress = mBtAdapter.getAddress();
    

这篇关于我怎样才能获得Android设备的唯一ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆