提交项目
This commit is contained in:
59
app/src/main/java/com/gh/common/util/DeviceUtils.java
Normal file
59
app/src/main/java/com/gh/common/util/DeviceUtils.java
Normal file
@ -0,0 +1,59 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class DeviceUtils {
|
||||
|
||||
public synchronized static String getDeviceHeader(Context context) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
|
||||
if (!TextUtils.isEmpty(imei)) {
|
||||
buffer.append("imei=" + imei);
|
||||
}
|
||||
String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
|
||||
if (!TextUtils.isEmpty(android_id)) {
|
||||
if (buffer.length() != 0) {
|
||||
buffer.append(",");
|
||||
}
|
||||
buffer.append("android_id=" + android_id);
|
||||
}
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
String mac = wm.getConnectionInfo().getMacAddress();
|
||||
if (!TextUtils.isEmpty(mac)) {
|
||||
if (buffer.length() != 0) {
|
||||
buffer.append(",");
|
||||
}
|
||||
buffer.append("mac=" + mac);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public synchronized static Map<String, String> getDeviceParams(Context context) {
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("imei", ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId());
|
||||
params.put("android_id", Secure.getString(context.getContentResolver(), Secure.ANDROID_ID));
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
params.put("mac", wm.getConnectionInfo().getMacAddress());
|
||||
return params;
|
||||
}
|
||||
|
||||
public synchronized static String getDeviceID(Context context) {
|
||||
String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
|
||||
if (!TextUtils.isEmpty(imei)) {
|
||||
return imei;
|
||||
}
|
||||
String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
|
||||
if (!TextUtils.isEmpty(android_id)) {
|
||||
return android_id;
|
||||
}
|
||||
return Installation.getUUID(context);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user