public class PhoneInfoUtil {
/**获取品牌*/
public static String getBrand() {
return android.os.Build.BRAND;
}
/**获取型号*/
public static String getModel() {
return android.os.Build.MODEL;
}
/**获取版本号*/
public static String getEdition() {
return android.os.Build.VERSION.RELEASE;
}
/**获取手机IMEI*/
public static String getIMEI(Context context) {
TelephonyManager manager= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getDeviceId();
}
/**获取运营商*/
public static String getOperator(Context context) {
TelephonyManager manager= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getSimOperatorName();
}
/**获取内存大小*/
public static String getMemory(Context context) {
String str1 = "/proc/meminfo";// 系统内存信息文件
String str2;
String[] arrayOfString;
long initial_memory = 0;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小
arrayOfString = str2.split("\\s+");
for (String num : arrayOfString) {
Log.i(str2, num + "\t");
}
initial_memory = Integer.valueOf(arrayOfString[1]) * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte
localBufferedReader.close();
} catch (IOException e) {
}
return Formatter.formatFileSize(context, initial_memory);// Byte转换为KB或者MB,内存大小规格化
}
/**获取IMSI*/
public static String getIMSI(Context context) {
TelephonyManager manager= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getSubscriberId();
}
/**获取手机号码*/
public static String getPhoneNumer(Context context) {
TelephonyManager manager= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getLine1Number();
}
/**获取手机当前内存大小*/
public static String getCurMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return Formatter.formatFileSize(context, mi.availMem);
}
/**CPU名字*/
public static String getCpuName() {
try {
FileReader fr = new FileReader("/proc/cpuinfo");
BufferedReader br = new BufferedReader(fr);
String text = br.readLine();
String[] array = text.split(":\\s+", 2);
for (int i = 0; i < array.length; i++) {
}
return array[1];
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**CPU最大频率*/
public static String getMaxCpuFreq() {
String result = "";
ProcessBuilder cmd;
try {
String[] args = {"/system/bin/cat",
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[24];
while (in.read(re) != -1) {
result = result + new String(re);
}
in.close();
} catch (IOException ex) {
ex.printStackTrace();
result = "N/A";
}
return result.trim() + "Hz";
}
/**获取CPU最小频率(单位KHZ)*/
public static String getMinCpuFreq() {
String result = "";
ProcessBuilder cmd;
try {
String[] args = {"/system/bin/cat",
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[24];
while (in.read(re) != -1) {
result = result + new String(re);
}
in.close();
} catch (IOException ex) {
ex.printStackTrace();
result = "N/A";
}
return result.trim() + "Hz";
}
/**实时获取CPU当前频率(单位KHZ)*/
public static String getCurCpuFreq() {
String result = "N/A";
try {
FileReader fr = new FileReader(
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
BufferedReader br = new BufferedReader(fr);
String text = br.readLine();
result = text.trim() + "Hz";
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}