应该不是很全,以后有时间再补充
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.telephony.TelephonyManager;
import android.text.format.Formatter;
import android.view.WindowManager;
import com.bh.resident.demo.MyApplication1;
import com.bh.resident.demo.utils.SLog;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
/**
* 读取基本信息
* Created by liyin on 2017-02-13.
*/
public class ReadDeviceInfoFunction {
TelephonyManager teleohonyManager;
Context context;
BatteryReceiver receiver;
@Override
public void init(Context context) {
this.context = context;
teleohonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
receiver =
new BatteryReceiver();
}
public void getDeviceInfo() {
SLog.Console(
"系统参数------------------------------begin");
String board = Build.BOARD;
SLog.Console(
"主板:" + board);
String brand = Build.BRAND;
SLog.Console(
"系统定制商:" + brand);
String device = Build.DEVICE;
SLog.Console(
"系统定制商:" + device);
String display = Build.DISPLAY;
SLog.Console(
"显示屏参数:" + display);
String fingderprint = Build.FINGERPRINT;
SLog.Console(
"唯一编号:" + fingderprint);
String serial = Build.SERIAL;
SLog.Console(
"硬件序列号:" + serial);
String id = Build.ID;
SLog.Console(
"修订版本列表:" + id);
String manufacturer = Build.MANUFACTURER;
SLog.Console(
"硬件制造商:" + manufacturer);
String model = Build.MODEL;
SLog.Console(
"版本:" + model);
String hardware = Build.HARDWARE;
SLog.Console(
"硬件名:" + hardware);
String product = Build.PRODUCT;
SLog.Console(
"手机产品名:" + product);
String tags = Build.TAGS;
SLog.Console(
"描述build的标签:" + tags);
String type = Build.TYPE;
SLog.Console(
"Builder类型:" + type);
String vcodename = Build.VERSION.CODENAME;
SLog.Console(
"当前开发代号:" + vcodename);
String vincremental = Build.VERSION.INCREMENTAL;
SLog.Console(
"源码控制版本号:" + vincremental);
String vrelease = Build.VERSION.RELEASE;
SLog.Console(
"版本字符串:" + vrelease);
int vsdkint = Build.VERSION.SDK_INT;
SLog.Console(
"版本号:" + vsdkint);
String host = Build.HOST;
SLog.Console(
"HOST值:" + host);
String user = Build.USER;
SLog.Console(
"User名:" + user);
long time = Build.TIME;
SLog.Console(
"编译时间:" +
new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss:SSS").format(
new Date(time)));
String osVersion = System.getProperty(
"os.version");
SLog.Console(
"OS版本号:" + osVersion);
String osName = System.getProperty(
"os.name");
SLog.Console(
"OS名称:" + osName);
String osArch = System.getProperty(
"os.arch");
SLog.Console(
"OS架构:" + osArch);
String osUserHome = System.getProperty(
"os.home");
SLog.Console(
"home属性:" + osUserHome);
String osUserName = System.getProperty(
"os.name");
SLog.Console(
"name属性 :" + osUserName);
String osUserDir = System.getProperty(
"os.dir");
SLog.Console(
"dir属性:" + osUserDir);
String osUserTimeZone = System.getProperty(
"os.timezone");
SLog.Console(
"时区:" + osUserTimeZone);
String phoneNum = teleohonyManager.getLine1Number();
SLog.Console(
"手机号:" + phoneNum);
String iccid = teleohonyManager.getSimSerialNumber();
SLog.Console(
"集成电路卡标识:" + iccid);
IntentFilter filter =
new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
MyApplication1.getInstance().registerReceiver(receiver, filter);
String mDeviceId = teleohonyManager.getDeviceId();
SLog.Console(
"设备id:" + mDeviceId);
getPhoneType();
getLocalMacAddress();
getLocalIpAddress();
getCpuInfo();
getTotalMemory();
getAvailMemory();
getWeithAndHeight();
}
/**
* 获取当前手机支持的移动网络类型
*/
private void getPhoneType() {
String phoneType =
"";
switch (teleohonyManager.getPhoneType()) {
case TelephonyManager.PHONE_TYPE_NONE:
phoneType =
"NONE: ";
break;
case TelephonyManager.PHONE_TYPE_GSM:
phoneType =
"GSM: IMEI";
break;
case TelephonyManager.PHONE_TYPE_CDMA:
phoneType =
"CDMA: MEID/ESN";
break;
default:
phoneType =
"UNKNOWN: ID";
break;
}
SLog.Console(
"手机网络类型:" + phoneType);
}
/**
* 获取mac地址
* 只有手机开启wifi才能获取到mac地址
*/
public void getLocalMacAddress() {
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
SLog.Console(
"MAC地址:" + info.getMacAddress());
}
/**
* 获取IP地址
*/
public void getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
SLog.Console(
"IP地址:" + inetAddress.getHostAddress().toString());
}
}
}
}
catch (SocketException ex) {
}
}
/**
* 手机CPU信息
*/
private void getCpuInfo() {
String str1 =
"/proc/cpuinfo";
String str2 =
"";
String[] cpuInfo = {
"",
""};
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) {
e.printStackTrace();
}
SLog.Console(
"cpu型号:" + cpuInfo[
0] +
"cpu频率:" + cpuInfo[
1]);
}
/**
* 获取当前可用内存大小
*/
private void getAvailMemory() {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi =
new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
SLog.Console(
"可用运行内存大小:" + Formatter.formatFileSize(context, mi.availMem));
}
/**
* 获得系统总内存
*/
private void getTotalMemory() {
File path = Environment.getDataDirectory();
StatFs stat =
new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
SLog.Console(
"总内存:" + Formatter.formatFileSize(context, blockSize * totalBlocks));
}
/**
* 获取屏幕宽高
*/
private void getWeithAndHeight() {
WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
int width = mWindowManager.getDefaultDisplay().getWidth();
int height = mWindowManager.getDefaultDisplay().getHeight();
SLog.Console(
"屏幕尺寸:" + width +
"x" + height);
}
private class BatteryReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
int current = intent.getExtras().getInt(
"level");
int total = intent.getExtras().getInt(
"scale");
int percent = current *
100 / total;
SLog.Console(
"电量:" + percent +
"%。");
context.unregisterReceiver(receiver);
}
}
}
}
欢迎 补充 修正