我想从Android设备获取唯一的设备ID。我想从Android设备获取该设备的唯一设备ID。
答案 0 :(得分:1)
是的,您可以获得android设备mac id,这被称为分配给网络接口的唯一标识符,用于物理网段上的通信,但这是每个设备的唯一ID,但不能更改。
你可以通过Android中的WIFImanager获取它
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = manager.getConnectionInfo();
String MACAddress = wifiInfo.getMacAddress();
不要忘记为清单文件添加权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"> </uses-permission>
答案 1 :(得分:1)
我认为没有任何(完美的)方法可以做到这一点。见link。如果您只想识别用户,可以生成一个UUID并将其存储在应用程序的存储中。
答案 2 :(得分:1)
创建了一次课程,并在我的应用中使用此功能,请参阅pastie
创建唯一ID并将MD5消息生成为唯一设备ID的字符串
public String getUDID(Context c) {
// Get some of the hardware information
String buildParams = Build.BOARD + Build.BRAND + Build.CPU_ABI
+ Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST
+ Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT
+ Build.TAGS + Build.TYPE + Build.USER;
// Requires READ_PHONE_STATE
TelephonyManager tm = (TelephonyManager) c
.getSystemService(Context.TELEPHONY_SERVICE);
// gets the imei (GSM) or MEID/ESN (CDMA)
String imei = tm.getDeviceId();
//gets the android-assigned id you can omit this because
//It's known to be null sometimes, it's documented as "can change upon factory reset".
//Use at your own risk, and it can be easily changed on a rooted phone.
String androidId = Secure.getString(c.getContentResolver(),
Secure.ANDROID_ID);
// requires ACCESS_WIFI_STATE
WifiManager wm = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
// gets the MAC address
String mac = wm.getConnectionInfo().getMacAddress();
// concatenate the string
String fullHash = buildParams + imei + androidId + mac;
return md5(fullHash);
}
md5(String fullHash)功能
public String md5(String toConvert) {
String retVal = "";
MessageDigest algorithm;
try {
algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(toConvert.getBytes());
byte messageDigest[] = algorithm.digest();
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
}
retVal = hexString + "";
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return retVal;
}
答案 3 :(得分:0)
这很简单,实际上......
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);