- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.LineNumberReader;
- 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;
- public class GetPhoneInfo {
- Context context;
- public GetPhoneInfo(Context context) {
- // TODO Auto-generated constructor stub
- this.context = context;
- }
- /**
- * 1.获取wifi mac 地址
- * */
- public String getWiFiMacInfo() {
- WifiManager wifi = (WifiManager) context
- .getSystemService(Context.WIFI_SERVICE);
- WifiInfo info = wifi.getConnectionInfo();
- String maxText = info.getMacAddress();
- //Log.d("GetInfo", "wifi mac = " + maxText);
- return maxText;
- }
- /**
- * 2.获取IMEI
- * */
- public String getImei() {
- TelephonyManager tm = (TelephonyManager) context
- .getSystemService(context.TELEPHONY_SERVICE);
- Log.d("GetInfo", "DeviceId = " + tm.getDeviceId());
- return tm.getDeviceId();
- }
- /**
- * 3.获取IMSI国际移动用户识别码,SIM卡唯一序列号,可能返回null
- */
- public String getMyImsi() {
- TelephonyManager tm = (TelephonyManager) context
- .getSystemService(context.TELEPHONY_SERVICE);
- //Log.d("GetInfo", "SubscriberId = " + tm.getSubscriberId());
- if (tm.getSubscriberId() != null) {
- return tm.getSubscriberId();
- } else {
- return "";
- }
- }
- /**
- * 4.获取AndroidID
- */
- public String getAndroidId() {
- String androidId = Settings.Secure.getString(
- context.getContentResolver(), Settings.Secure.ANDROID_ID);
- //Log.d("GetInfo", "androidId = " + androidId);
- return androidId;
- }
- /**
- * 5.获取SSN,所有CDMA设备返回NULL,
- */
- public String getSSN() {
- TelephonyManager tm = (TelephonyManager) context
- .getSystemService(context.TELEPHONY_SERVICE);
- //Log.d("GetInfo", "SSN = " + tm.getSimSerialNumber());
- if (tm.getSimSerialNumber() != null) {
- return tm.getSimSerialNumber();
- } else {
- return "";
- }
- }
- //
- // /**
- // *
- // * 6.取imei androidID 结合UUID并加密
- // * */
- // private String getOnlyFlag() {
- // String a = getAndroidId();
- // String b = getImei();
- // String c = getSSN();
- // UUID deviceUuid = new UUID(getAndroidId().hashCode(),
- // ((long) getImei().hashCode() << 32) | getSSN().hashCode());
- // String uniqueId = deviceUuid.toString();
- // Log.d("GetInfo", "uniqueId = " + uniqueId);
- // return uniqueId;
- // }
- // =======================================================以下是获取硬件设备信息
- /**
- * 6.1.获取CPU序列号
- *
- * @return CPU序列号(16位) 读取失败为"0000000000000000"
- */
- public String getCPUSerial() {
- String str = "", strCPU = "", cpuAddress = "0000000000000000";
- try {
- // 读取CPU信息
- Process pp = Runtime.getRuntime().exec("cat /proc/cpuinfo");
- InputStreamReader ir = new InputStreamReader(pp.getInputStream());
- LineNumberReader input = new LineNumberReader(ir);
- // 查找CPU序列号
- for (int i = 1; i < 100; i++) {
- str = input.readLine();
- if (str != null) {
- // 查找到序列号所在行
- if (str.indexOf("Serial") > -1) {
- // 提取序列号
- strCPU = str.substring(str.indexOf(":") + 1,
- str.length());
- // 去空格
- cpuAddress = strCPU.trim();
- break;
- }
- } else {
- // 文件结尾
- break;
- }
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- //Log.d("GetInfo", "cpuAddress = " + cpuAddress);
- return cpuAddress;
- }
- // 6.2获取CPU型号
- public String getCpuInfo() {
- String str1 = "/proc/cpuinfo";
- String str2 = "";
- String cpuModel = "";
- String[] arrayOfString;
- try {
- FileReader fr = new FileReader(str1);
- BufferedReader localBufferedReader = new BufferedReader(fr, 8192);
- str2 = localBufferedReader.readLine();
- arrayOfString = str2.split("\\s+");
- for (int i = 2; i < arrayOfString.length; i++) {
- cpuModel = cpuModel + arrayOfString[i] + " ";
- }
- localBufferedReader.close();
- } catch (IOException e) {
- }
- return cpuModel;
- }
- }