Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获取android设备的唯一ID?_Android - Fatal编程技术网

如何获取android设备的唯一ID?

如何获取android设备的唯一ID?,android,Android,可能重复: 我使用下面的代码来获取android设备IMEI,如何更改下面的代码来获取android设备的唯一ID String getDeviceID1(TelephonyManager phonyManager){ String id = phonyManager.getDeviceId(); if (id == null){ id = "not available"; } int phoneType = phonyManager.getPh

可能重复:

我使用下面的代码来获取android设备IMEI,如何更改下面的代码来获取android设备的唯一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));
}

在Android中,您可以获得三个不同的唯一ID

  • IMEI(代码中已经有了)

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


要更改IMEI吗????为什么?@Eric,这不是重复的任务,这不是一个真正的问题。@Lucifer用他说话的方式,听起来他想改变它以获得一个不同的唯一设备ID,这在那篇文章中有介绍。。。所以,我想这取决于你如何解释这个问题。不管怎样,投票结束就是投票结束。@Luciier:他不想改变IMEI。他的意思是说,他已经成功地实施了获得IMEI的计划。他要求在程序中更改什么以获得唯一的设备ID而不是IMEI。@Lucifer我的意思是,我不想在我的应用程序中再显示IMEI。我必须显示android唯一的设备id。谢谢。如何在脚本中更改蓝牙地址?您所说的更改是什么意思,我没有正确地理解您。我的意思是我应该在脚本中添加蓝牙地址脚本。当然,在您需要唯一id的位置添加它。哇!我明白了,谢谢你,路西法
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String id =  (getDeviceID1(telephonyManager));
String android_id = Secure.getString(getContext().getContentResolver(),
                                                Secure.ANDROID_ID); 
private BluetoothAdapter mBtAdapter;

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