GetDevicesUtil.java
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.hjx.personalcenter.util;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.hjx.personalcenter.model.DeviceInfo;
public class GetDevicesUtil {
private final static String LOG_TAG = "GetDevicesUtil";
public static DeviceInfo getDevicesInfo(Context context){
DeviceInfo mDeviceInfo = new DeviceInfo();
initDevicesInfo(mDeviceInfo,context);
return mDeviceInfo;
}
public static void initDevicesInfo(DeviceInfo mDeviceInfo,Context context){
mDeviceInfo.setDeviceModel(android.os.Build.MODEL);
Log.e(LOG_TAG,"" + mDeviceInfo.getDeviceModel());
mDeviceInfo.setMac(getMacAddress(context));
Log.e(LOG_TAG,"" + mDeviceInfo.getMac());
mDeviceInfo.setDeviceNumber(getCPUSerial(context));
Log.e(LOG_TAG,"" + mDeviceInfo.getDeviceNumber());
}
private static String getCPUSerial(Context context) {
String cpuAddress = null;
TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null) {
cpuAddress = mTelephony.getDeviceId();
} else {
//android.provider.Settings;
cpuAddress = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
}
return cpuAddress;
}
private static String getMacAddress(Context mContext){
String ret = null;
try {
WifiManager manager = (WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = manager.getConnectionInfo();
ret = info.getMacAddress();
} catch (Exception e) {
Log.e(LOG_TAG, "get wifi address wrong", e);
}
Log.i(LOG_TAG, "wifi address is" + ret);
return ret;
}
}