获取手机相关信息:
TelephonyManager mTm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String imei = mTm.getDeviceId(); //设置imei号
String mtype = android.os.Build.MODEL; // 手机型号
String numer = mTm.getLine1Number(); // 手机号码,有的可得,有的不可得
需加入权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
手机宽和高:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
String width = dm.widthPixels; /宽
String height = dm.heightPixels; //高
mac地址:
String result = "";
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
result = wifiInfo.getMacAddress();
Log.i(TAG, "macAdd:" + result);
return result;
cup信息:
String str1 = "/proc/cpuinfo";
String str2 = "";
String[] cpuInfo = {"", ""}; //1-cpu型号 //2-cpu频率
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++) {
cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " ";
}
str2 = localBufferedReader.readLine();
arrayOfString = str2.split("//s+");
cpuInfo[1] += arrayOfString[2];
localBufferedReader.close();
} catch (IOException e) {
}
Log.i(TAG, "cpuinfo:" + cpuInfo[0] + " " + cpuInfo[1]);
return cpuInfo;
String[] result = {"",""}; //1-total 2-avail
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
mActivityManager.getMemoryInfo(mi);
long mTotalMem = 0;
long mAvailMem = mi.availMem;
String str1 = "/proc/meminfo";
String str2;
String[] arrayOfString;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
str2 = localBufferedReader.readLine();
arrayOfString = str2.split("//s+");
mTotalMem = Integer.valueOf(arrayOfString[1]).intValue() * 1024;
localBufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
result[0] = Formatter.formatFileSize(this, mTotalMem);
result[1] = Formatter.formatFileSize(this, mAvailMem);
Log.i(TAG, "meminfo total:" + result[0] + " used:" + result[1]);
return result;
获取手机安装的应用信息(排除系统自带):
String result = "";
List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
for (PackageInfo i : packages) {
if ((i.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
result += i.applicationInfo.loadLabel(getPackageManager()).toString() + ",";
}
}
return result.substring(0, result.length() - 1);