想要获取Android手机里的一些常用参数的亲们,你们有福了,这里给出网罗了一天的手机参数给大家。
参数过多,我就不分开给,把所有代码粘贴上来,大家可以把代码复制到项目上,通过检索可以很容易找到自己要的参数
MainActivity
public class MainActivity extends ActionBarActivity {
private EditText etfenbian, etxiangsu, etimei, etsddaxiao, etsdxiandaxiao,
etsimyun, etipwai, etipnei, shoujinei, shoujineisheng, etxinghao,
etandroidbanben, etdianchidian, etCPU, etjidaibanben,
etneihebanben, etMIUI, etsimnumber, etTime, wangluo, wangluoshouji,
wangluoWifi, etjinchengshu, shoujixinxi, chuanganqi, etlanya,
jingweidu, jizhanxinxi,kaijishijian,yingyong;
public Context context;
private TextView getwifiview;
String ipwai, ipnei;
private final static String kCpuInfoMaxFreqFilePath = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
// 注册广播接受者java代码
IntentFilter intentFilter = new IntentFilter(
Intent.ACTION_BATTERY_CHANGED);
// 创建广播接受者对象
BatteryReceiver batteryReceiver = new BatteryReceiver();
// 注册receiver
registerReceiver(batteryReceiver, intentFilter);
//初始化所有组件
init();
//获取分辨率
getfenbianlv();
//获取手机IMEI号
getimei();
//获取SD卡储存大小
getsddaxiao();
//获取SIM卡运营商
getsimyun();
//获取IP外网
ipwai();
//获取内网IP
ipnei();
//获取手机内存
shoujinei();
//获取手机型号版本
getxinhaobanben();
//获取CPU主频
getCUP();
jidaibanben();// 基带版本
getneihe();// 内核版本
//获取MIUI版本
getMIUI();
//获取手机摄像头支持的分辨率
getxiangsu();
//获取SIM卡卡号
getSimNumber();
//获取系统时间
getTime();
//判断手机网络使用状态
shouwanluo();
//获取手机进程数
getjinchengshu();
//获取手机基本信息
getshoujiINfo();
//获取手机传感器
getchuanganqi();
//获取蓝牙信息
getlanya();
//获取手机经纬度
getjingwei();
//获取手机基站信息,要有SIM卡的手机
getjizhang();
//获取手机开机时间
getStartTime();
//获取应用名称
applyName();
// Pixels();
}
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
String result=msg.getData().getString("JINWEI");
jingweidu.setText(result);
}
};
private void init() {
etfenbian = (EditText) findViewById(R.id.et_fenbian);
etxiangsu = (EditText) findViewById(R.id.et_xiangsu);
etimei = (EditText) findViewById(R.id.et_imei);
etsddaxiao = (EditText) findViewById(R.id.et_sddaxiao);
etsdxiandaxiao = (EditText) findViewById(R.id.et_sdxiandaxiao);
etsimyun = (EditText) findViewById(R.id.et_sdyun);
etipwai = (EditText) findViewById(R.id.et_ipwai);
etipnei = (EditText) findViewById(R.id.et_ipnei);
shoujinei = (EditText) findViewById(R.id.et_shoujinei);
shoujineisheng = (EditText) findViewById(R.id.et_shoujineisheng);
etxinghao = (EditText) findViewById(R.id.et_xinghao);
etandroidbanben = (EditText) findViewById(R.id.et_androidbanben);
etdianchidian = (EditText) findViewById(R.id.et_dianchidian);
etCPU = (EditText) findViewById(R.id.et_CPU);
etjidaibanben = (EditText) findViewById(R.id.et_jidaibanben);
etneihebanben = (EditText) findViewById(R.id.et_neihebanben);
etMIUI = (EditText) findViewById(R.id.et_MIUI);
etsimnumber = (EditText) findViewById(R.id.et_simnumber);
etTime = (EditText) findViewById(R.id.et_Time);
wangluo = (EditText) findViewById(R.id.et_wangluo);
wangluoshouji = (EditText) findViewById(R.id.et_wangluoshouji);
wangluoWifi = (EditText) findViewById(R.id.et_wangluoWifi);
etjinchengshu = (EditText) findViewById(R.id.et_jinchengshu);
shoujixinxi = (EditText) findViewById(R.id.et_shoujixinxi);
chuanganqi = (EditText) findViewById(R.id.et_chuanganqi);
etlanya = (EditText) findViewById(R.id.et_lanya);
jingweidu = (EditText) findViewById(R.id.et_jingweidu);
jizhanxinxi = (EditText) findViewById(R.id.et_jizhanxinxi);
getwifiview = (TextView) findViewById(R.id.getwifi);
kaijishijian=(EditText) findViewById(R.id.et_kaijishijian);
yingyong=(EditText) findViewById(R.id.et_yingyong);
getwifiview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// WIFI详细信息
startActivity(new Intent(MainActivity.this, WiFiActivity.class));
}
});
}
/*
* 获取手机应用名称
*/
private void applyName()
{
PackageManager localPackageManager = this.getPackageManager();
ApplicationInfo localApplicationInfo;
try {
localApplicationInfo = localPackageManager
.getApplicationInfo(this.getPackageName(), 0);
String P = localApplicationInfo.loadLabel(localPackageManager)
.toString();
yingyong.setText(P);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
* 获取手机开机时间
*/
private void getStartTime() {
long ut = SystemClock.elapsedRealtime() / 1000;
if (ut == 0) {
ut = 1;
}
int m = (int) ((ut / 60) % 60);
int h = (int) ((ut / 3600));
int day = h / 24;
h -= day * 24;
String time = null;
if (day == 0) {
if (h == 0) {
time = m + "分";
} else {
time = h + "小时" + m + "分";
}
} else {
time = day + "天" + h + "小时" + m + "分";
}
kaijishijian.setText(time);
}
/*
* 获取传感器
*/
private void getchuanganqi() {
String string = SensorMg.get(this);
chuanganqi.setText(string);
}
/*
* 获取手机基本信息
*/
private void getshoujiINfo() {
String info = SystemInfoUtils.getPhoneInfo();
shoujixinxi.setText(info);
}
/*
* 获取系统进程数
*/
private void getjinchengshu() {
long count = SystemInfoUtils.getRunningProcessCount(this);
etjinchengshu.setText(Long.toString(count));
}
/*
* 获取蓝牙版本
*/
private void getlanya()
{
String btMac = BtMac.getBtMac(this);
etlanya.setText(btMac);
}
/*
* 获取经纬度
*/
LocationManager locationManager;
private String mStrPos = "经纬度";
private void getjingwei()
{
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
new Thread() {
@Override
public void run() {
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
double latitude = location.getLatitude(); // 经度
double longitude = location.getLongitude(); // 纬度
mStrPos = "经纬度" + "\n纬度:" + latitude + "\n经度: " + longitude;
Message msg=new Message();
Bundle b=new Bundle();
b.putString("JINWEI", mStrPos);
msg.setData(b);
handler.sendMessage(msg);
}
}
}.start();
}
/*
* 获取系统时间
*/
private void getTime() {
etTime.setText(TimeZoo.gettime1() + "(" + TimeZoo.get() + ")");
}
/*
* 获取屏幕分辨率
*/
private void getfenbianlv() {
//这种方式也能得到手机屏幕的分辨率
// DisplayMetrics metrics = new DisplayMetrics();
// getWindowManager().getDefaultDisplay().getMetrics(metrics);
// int widthPixels = metrics.widthPixels;
// int heightPixels = metrics.heightPixels;
// etfenbian.setText(widthPixels + "*" + heightPixels);
DisplayMetrics metric = new DisplayMetrics();
Display display = getWindowManager().getDefaultDisplay();
getWindowManager().getDefaultDisplay().getMetrics(metric);
float density = metric.density; // 屏幕密度(0.75 / 1.0 / 1.5)
int densityDpi = metric.densityDpi; // 屏幕密度DPI(120 / 160 / 240)
int width = display.getWidth();
int height = display.getHeight();
StringBuffer sb = new StringBuffer();
sb.append("屏幕像素:" + width + "*" + height);
sb.append("\n屏幕密度:" + density);
sb.append("\n屏幕密度DPI:" + densityDpi);
etfenbian.setText(sb);
}
public static boolean isNetworkAvalible(Context context) {
// 获得网络状态管理器
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) {
return false;
} else {
// 建立网络数组
NetworkInfo[] net_info = connectivityManager.getAllNetworkInfo();
if (net_info != null) {
for (int i = 0; i < net_info.length; i++) {
// 判断获得的网络状态是否是处于连接状态
if (net_info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
public void shouwanluo() {
if (isNetworkAvalible(this)) {
wangluo.setText("是");
// 获取wifi服务
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (wifiManager.isWifiEnabled()) {
wangluoWifi.setText("是");
wangluoshouji.setText("否");
} else {
wangluoshouji.setText("是");
wangluoWifi.setText("否");
}
} else {
wangluo.setText("否");
wangluoWifi.setText("否");
wangluoshouji.setText("否");
}
}
/*
* 获取像素
*/
private String cameraInfo = "摄像头信息";
private void getxiangsu() {
Camera camera = Camera.open();
Camera.Parameters parameters = camera.getParameters();
List<Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();//获得摄像头支持预览的各种分辨率
List<Size> supportedPictureSizes = parameters.getSupportedPictureSizes();//摄像头支持的图片尺寸
StringBuffer sb = new StringBuffer();
sb.append("摄像头支持预览的各种分辨率:");
for (Size size : supportedPreviewSizes) {
int height = size.height;
int width = size.width;
sb.append("\n" + width + "/" + height);
}
sb.append("\n\n摄像头支持的图片尺寸:");
for (Size size : supportedPictureSizes) {
int height = size.height;
int width = size.width;
sb.append("\n" + width + "/" + height);
}
cameraInfo = sb.toString();
etxiangsu.setText(cameraInfo);
}
/*
* 获取型号以及版本
*/
private void getxinhaobanben() {
etxinghao.setText(android.os.Build.MODEL);
etandroidbanben.setText(android.os.Build.VERSION.RELEASE);
}
/**
* 220 获取SIM卡号 221
*
* 222 用到的权限: 223 <uses-permission
* android:name="android.permission.READ_PHONE_STATE" /> 224
*/
/*
* 获取SIM卡卡号
*/
public void getSimNumber() {
String strResult = "";
TelephonyManager telephonyManager = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
strResult = telephonyManager.getSimSerialNumber();
}
if (strResult == null) {
etsimnumber.setText("没检测到SIM卡");
} else {
etsimnumber.setText(strResult);
}
}
/** 基站信息结构体 */
public class SCell {
public int MCC;
public int MNC;
public int LAC;
public int CID;
}
/**
* 获取基站信息
*
* @throws Exception
*/
public SCell getCellInfo(Context context) throws Exception {
SCell cell = new SCell();
/** 调用API获取基站信息 */
TelephonyManager mTelNet = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation location = (GsmCellLocation) mTelNet.getCellLocation();
if (location == null)
throw new Exception("获取基站信息失败");
String operator = mTelNet.getNetworkOperator();
int mcc = Integer.parseInt(operator.substring(0, 3));
int mnc = Integer.parseInt(operator.substring(3));
int cid = location.getCid();
int lac = location.getLac();
/** 将获得的数据放到结构体中 */
cell.MCC = mcc;
cell.MNC = mnc;
cell.LAC = lac;
cell.CID = cid;
return cell;
}
/*
* 获取基站信息
*/
SCell c;
public void getjizhang() {
StringBuffer stb=new StringBuffer();
try {
c=getCellInfo(this);
if(stb!=null)
{
stb.append("MCC:"+c.MCC);
stb.append("\nMNC:"+c.MNC);
stb.append("\nLAC"+c.LAC);
stb.append("\nCID:"+c.CID);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
jizhanxinxi.setText(stb);
}
/*
* 获取CUP主频
*/
private void getCUP() {
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";
}
int a = Integer.parseInt(result.trim());
int b = a / (1000 * 1000);
int c = (int) ((((a + (0.5 * 1000 * 100)) / (1000 * 100))) % 10);
etCPU.setText(b + "." + c + "GHz");
}
/*
* 获取IMEI号
*/
private void getimei() {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager.getDeviceId();
etimei.setText(imei);
}
/**
* INNER-VER MIUI版本 return String
*/
public void getMIUI() {
String ver = "";
if (android.os.Build.DISPLAY
.contains(android.os.Build.VERSION.INCREMENTAL)) {
ver = android.os.Build.DISPLAY;
} else {
ver = android.os.Build.VERSION.INCREMENTAL;
}
etMIUI.setText(ver);
}
/**
* INNER-VER 内核版本 return String
*/
public void getneihe() {
Process process = null;
String kernelVersion = "";
try {
process = Runtime.getRuntime().exec("cat /proc/version");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// get the output line
InputStream outs = process.getInputStream();
InputStreamReader isrout = new InputStreamReader(outs);
BufferedReader brout = new BufferedReader(isrout, 8 * 1024);
String result = "";
String line;
// get the whole standard output string
try {
while ((line = brout.readLine()) != null) {
result += line;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if (result != "") {
String Keyword = "version ";
int index = result.indexOf(Keyword);
line = result.substring(index + Keyword.length());
index = line.indexOf(" ");
kernelVersion = line.substring(0, index);
}
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
etneihebanben.setText(kernelVersion);
}
/**
* 基带版本
*/
public void jidaibanben() {
String Version = "";
try {
Class cl = Class.forName("android.os.SystemProperties");
Object invoker = cl.newInstance();
Method m = cl.getMethod("get", new Class[] { String.class,
String.class });
Object result = m.invoke(invoker, new Object[] {
"gsm.version.baseband", "no message" });
// System.out.println(">>>>>>><<<<<<<" +(String)result);
Version = (String) result;
} catch (Exception e) {
}
etjidaibanben.setText(Version);
}
/*
* 获取SD卡大小
*/
private void getsddaxiao() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File sdcardDir = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(sdcardDir.getPath());
long blockSize = sf.getBlockSize();
long blockCount = sf.getBlockCount();
long availCount = sf.getAvailableBlocks();
// SD卡总内存KB
long a = blockCount * blockSize / 1024;
// SD卡剩余内存GB
long b = availCount * blockSize / 1024;
etsddaxiao.setText(KandG(a));
etsdxiandaxiao.setText(KandG(b));
}
// Log.d("", "block大小:"+ blockSize+",block数目:"+
// blockCount+",总大小:"+blockSize*blockCount/1024+"KB");
// Log.d("", "可用的block数目::"+ availCount+",剩余空间:"+
// availCount*blockSize/1024+"KB");
}
/*
* 获取SIM运营商
*/
private void getsimyun() {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String operator = null;
String IMSI = tm.getSubscriberId();
if (IMSI == null || IMSI.equals("")) {
operator = "没检测到SIM卡";
} else {
if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
operator = "中国移动";
} else if (IMSI.startsWith("46001")) {
operator = "中国联通";
} else if (IMSI.startsWith("46003")) {
operator = "中国电信";
}
}
etsimyun.setText(operator);
}
/*
* 获取IP外网
*/
private void ipwai() {
NetIPUtil net = new NetIPUtil(this);
net.initNetIP();
net.setGetNetIpListner(new GetNetIpListner() {
@Override
public void getOk(String newNetIP) {
// TODO Auto-generated method stub
etipwai.setText(newNetIP + ")");
}
@Override
public void getFail(String result) {
// TODO Auto-generated method stub
etipwai.setText("获取不到外网IP");
}
});
}
/*
* 获取IP内网
*/
private void ipnei() {
// 获取wifi服务
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
// 判断wifi是否开启
if (wifiManager.isWifiEnabled()) {
// wifiManager.setWifiEnabled(true);
Toast.makeText(MainActivity.this, "-------", Toast.LENGTH_SHORT)
.show();
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
String ip = intToIp(ipAddress);
etipnei.setText(ip + "(WIFI)");
} else {
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()) {
String ip = inetAddress.getHostAddress().toString();
etipnei.setText(ip + "GPRS");
}
}
}
} catch (SocketException ex) {
Log.e("WifiPreference IpAddress", ex.toString());
}
}
}
private String intToIp(int i) {
return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF)
+ "." + (i >> 24 & 0xFF);
}
/*
* 获取手机内存
*/
private void shoujinei() {
File root = Environment.getRootDirectory();
StatFs sf = new StatFs(root.getPath());
long blockSize = sf.getBlockSize();
long blockCount = sf.getBlockCount();
long availCount = sf.getAvailableBlocks();
// 手机总内存KB
long a = blockCount * blockSize / 1024;
// 手机剩余内存GB
long b = availCount * blockSize / 1024;
shoujinei.setText(KandG(a));
shoujineisheng.setText(KandG(b));
}
/*
* 内存单位K转化为G转化的方法
*/
private String KandG(long str) {
String result = null;
int a = (int) ((str * 10 / (1024 * 1024)) + 0.5);
int b = a / 10;
int c = a % 10;
result = b + "." + c + "G";
return result;
}
/**
* 广播接受者
*/
class BatteryReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
// 判断它是否是为电量变化的Broadcast Action
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
// 获取当前电量
int level = intent.getIntExtra("level", 0);
// 电量的总刻度
int scale = intent.getIntExtra("scale", 100);
// 把它转成百分比
etdianchidian.setText(((level * 100) / scale) + "%");
}
}
}
}
还有一些帮助类,一些参数的获取逻辑我另外写在这些类中。
BtMac类
public class BtMac {
public static String getBtMac(Context context) {
WifiManager mWifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
String btMac;
if (!mWifi.isWifiEnabled()) {
mWifi.setWifiEnabled(true);
}
WifiInfo wifiInfo = mWifi.getConnectionInfo();
BluetoothAdapter bAdapt = BluetoothAdapter.getDefaultAdapter();
if (bAdapt != null) {
btMac = bAdapt.getAddress();
} else {
btMac = "No Bluetooth Device!";
}
return "蓝牙MAC: " + btMac;
}
}
Longitude类
public class Longitude {
public static String init(Context context)
{
Location location=null;
//获得位置服务的名称
String serviceName = context.LOCATION_SERVICE;
//获得位置服务的管理对象
LocationManager locationManager = (LocationManager)context.getSystemService(serviceName);
// 通过GPS获取定位的位置数据
location = locationManager.getLastKnownLocation(locationManager.GPS_PROVIDER);
String number=null;
if (location != null) {
double latitude = location.getLatitude();
double longitude= location.getLongitude();
number="经度:"+latitude+"纬度:"+longitude;
} else {
number="无法获取经纬度";
}
return number;
}
}
NetIPUtil类
public class NetIPUtil {
private Activity activity;
private GetNetIpListner listener;
private final String URL_NET_IP = "http://1212.ip138.com/ic.asp";
private final String CHARSET_GBK = "gbk";
private String newNetIp;
public NetIPUtil(Activity context) {
activity = context;
}
/**
* 获取外网IP
*
* @return <br>
*/
private String setNetIp() {
newNetIp = null;
URL infoUrl = null;
InputStream inStream = null;
try {
infoUrl = new URL(URL_NET_IP);
HttpURLConnection conn = (HttpURLConnection) infoUrl.openConnection();
conn.setRequestMethod("GET");
conn.setReadTimeout(5000);
conn.setConnectTimeout(5000);
int responseCode = conn.getResponseCode();
if (responseCode == 200) {
inStream = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, CHARSET_GBK));
StringBuilder strber = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
strber.append(line + "\n");
inStream.close();
// 从反馈的结果中提取出IP地址
int start = strber.indexOf("[");
int end = strber.indexOf("]", start + 1);
String a = strber.substring(start + 1, end);
int i = 3 + strber.indexOf("来自:");
int j = strber.indexOf("</center>");
String b = strber.substring(i, j);
line=a+"("+b;
if (!TextUtils.isEmpty(line))
newNetIp = line;
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
return e.toString();
} catch (IOException e) {
e.printStackTrace();
return e.toString();
}
return null;
}
public void setGetNetIpListner(GetNetIpListner listner) {
this.listener = listner;
}
public interface GetNetIpListner {
public void getFail(String result);
/**
*
* @param newNetIP
* <br>
* 新的外网IP
*/
public void getOk(String newNetIP);
}
/**
* 获取外网IP
*/
public void initNetIP() {
new Thread(new Runnable() {
public void run() {
final String result = setNetIp();
activity.runOnUiThread(new Runnable() {
public void run() {
if (newNetIp != null) {
listener.getOk(newNetIp);
} else {
listener.getFail(result);
}
}
});
}
}).start();
}
}
SensorMg类
public class SensorMg {
public static String get(Context context) {
SensorManager sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
// 声明可变字符串
StringBuffer sb = new StringBuffer();
List<Sensor> sensorList = sm.getSensorList(Sensor.TYPE_ALL);
for (Sensor sensor : sensorList) {
String name = sensor.getName().toString();
if ("Gyroscope".equals(name)) {
name = name + " 陀螺仪";
}
if ("Raw Gyroscope".equals(name)) {
name = name + " 原始陀螺仪";
}
if ("Accelerometer".equals(name)) {
name = name + " 加速传感器";
}
if ("Magnetic Field".equals(name)) {
name = name + " 磁场传感器";
}
if ("Orientation".equals(name)) {
name = name + " 方位传感器";
}
if ("Rotation Vector".equals(name)) {
name = name + " 矢量旋转传感器";
}
if ("Linear Acceleration".equals(name)) {
name = name + " 直线加速传感器";
}
if ("Gravity".equals(name)) {
name = name + " 重力传感器";
}
if ("Light Sensor".equals(name)) {
name = name + " 亮度传感器";
}
if ("Proximity".equals(name)) {
name = name + " 接近传感器";
}
sb.append(name);
sb.append("\n");
}
return sb.toString();
}
}
SystemInfoUtils类
public class SystemInfoUtils {
/**
* 获取正在运行的进程的个数
*
* @return 进程数量
*/
public static int getRunningProcessCount(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
return am.getRunningAppProcesses().size();
}
/**
* 获取手机可用的内存信息 ram
*
* @param context
* @return 单位是byte
*/
public static long getAvailRam(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo outInfo = new ActivityManager.MemoryInfo();
am.getMemoryInfo(outInfo);
return outInfo.availMem; // byte为单位的long类型的可用内存大小
}
/**
* 获取手机总内存信息 ram
*
* @param context
* @return 单位是byte
*/
public static long getTotalRam(Context context) {
// 下面的api totalmem只能在16以上版本下使用。
// ActivityManager am = (ActivityManager)
// context.getSystemService(Context.ACTIVITY_SERVICE);
// MemoryInfo outInfo = new ActivityManager.MemoryInfo();
// am.getMemoryInfo(outInfo);
// return outInfo.totalMem;
try {
File file = new File("/proc/meminfo");
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
// MemTotal: 516452 kB
String line = br.readLine();
// 字符串 一组字符--串
StringBuffer sb = new StringBuffer();
for (char c : line.toCharArray()) {
if (c >= '0' && c <= '9') {
sb.append(c);
}
}
return Integer.parseInt(sb.toString()) * 1024l; // byte
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* 获取手机内部存储信息
*
* @param view
* @return
*/
public static String[] memeoryInfo(Context context) {
File storageDirectory = Environment.getDataDirectory();
StatFs fs = new StatFs(storageDirectory.getAbsolutePath());
long blockCount = fs.getBlockCount();
long blockSize = fs.getBlockSize();
long availableBlocks = fs.getAvailableBlocks();
long avaiSizeFs = availableBlocks * blockSize;
long totalSizeFs = blockCount * blockSize;
String totalSizeFsString = Formatter.formatFileSize(context, totalSizeFs);
String avaiSizeFsString = Formatter.formatFileSize(context, avaiSizeFs);
String[] str_array = new String[2];
str_array[0] = avaiSizeFsString;
str_array[1] = totalSizeFsString;
return str_array;
}
/**
* 获取SDCard内存信息
*
* @param view
* @return
*/
public static String[] sdCardInfo(Context context) {
File storageDirectory = Environment.getExternalStorageDirectory();
StatFs fs = new StatFs(storageDirectory.getAbsolutePath());
long blockCount = fs.getBlockCount();
long blockSize = fs.getBlockSize();
long availableBlocks = fs.getAvailableBlocks();
long avaiSizeFs = availableBlocks * blockSize;
long totalSizeFs = blockCount * blockSize;
String totalSizeFsString = Formatter.formatFileSize(context, totalSizeFs);
String avaiSizeFsString = Formatter.formatFileSize(context, avaiSizeFs);
String[] str_array = new String[2];
str_array[0] = avaiSizeFsString;
str_array[1] = totalSizeFsString;
return str_array;
}
public static String getPhoneInfo() {
String phoneInfo = "产品名称: " + android.os.Build.PRODUCT;
phoneInfo += "\nCPU型号: " + android.os.Build.CPU_ABI;
phoneInfo += "\n标签: " + android.os.Build.TAGS;
phoneInfo += "\n手机型号: " + android.os.Build.MODEL;
phoneInfo += "\nSDK版本: " + android.os.Build.VERSION.SDK;
phoneInfo += "\n系统版本: " + android.os.Build.VERSION.RELEASE;
phoneInfo += "\n设备驱动: " + android.os.Build.DEVICE;
phoneInfo += "\n显示: " + android.os.Build.DISPLAY;
phoneInfo += "\n品牌: " + android.os.Build.BRAND;
phoneInfo += "\n主板: " + android.os.Build.BOARD;
phoneInfo += "\n\n指纹: " + android.os.Build.FINGERPRINT;
phoneInfo += "\n\nID: " + android.os.Build.ID;
phoneInfo += "\n制造商: " + android.os.Build.MANUFACTURER;
phoneInfo += "\n用户组: " + android.os.Build.USER;
return phoneInfo;
}
}
TelephonyMg
public class TelephonyMg {
public static void getCallState(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int callState = tm.getCallState();
String state = null;
switch (callState) {
case TelephonyManager.CALL_STATE_IDLE:
state = "电话闲置";
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
state = "电话接通";
break;
case TelephonyManager.CALL_STATE_RINGING:
state = "有电话进入";
break;
default:
break;
}
}
public static String getPhoneNumber(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return tm.getLine1Number();
}
public static String getPhoneType(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int phoneType = tm.getPhoneType();
String type = null;
switch (phoneType) {
case TelephonyManager.PHONE_TYPE_CDMA:
type = "CDMA信号";
break;
case TelephonyManager.PHONE_TYPE_GSM:
type = "GSM信号";
break;
case TelephonyManager.PHONE_TYPE_NONE:
type = "无信号";
break;
case TelephonyManager.PHONE_TYPE_SIP:
type = "SIP信号";
break;
default:
break;
}
return type;
}
public static String getSimOperatorName(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int state = tm.getSimState();
String simOperatorName = null;
if (TelephonyManager.SIM_STATE_READY == state) {
simOperatorName = tm.getSimOperatorName();
} else {
simOperatorName = "没有检测到SIM卡";
}
return simOperatorName;
}
// ICCID:Integrate circuit card identity 集成电路卡识别码(固化在手机SIM卡中)
// ICCID为IC卡的唯一识别号码,共有20位数字组成,其编码格式为:XXXXXX 0MFSS YYGXX XXXXX。分别介绍如下:
// 前六位运营商代码:中国移动的为:898600;898602 ,中国联通的为:898601,中国电信898603
// ICCID的号码 SIM卡的序号
public static String getSimSerialNumber(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
boolean hasIccCard = tm.hasIccCard();
String simSerialNumber = null;
if (hasIccCard) {
simSerialNumber = tm.getSimSerialNumber();
} else {
simSerialNumber = "没有检测到SIM卡";
}
return simSerialNumber;
}
}
TimeZoo类
public class TimeZoo {
public static String get() {
TimeZone timeZone = TimeZone.getDefault();
String id = timeZone.getID();
return id;
}
public static String gettime1()
{
SimpleDateFormat fomat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
String str = fomat.format(curDate);
return str;
}
}
WiFiActivity类
public class WiFiActivity extends Activity{
private final String TAG = "MainActivity";
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
TextView ssidTextView = (TextView) findViewById(R.id.activity_main_ssid_textview);
TextView bssidTextView = (TextView) findViewById(R.id.activity_main_bssid_textview);
TextView macTextView = (TextView) findViewById(R.id.activity_main_mac_textview);
TextView linkSpeedTextView = (TextView) findViewById(R.id.activity_main_link_speed_textview);
TextView rssiTextView = (TextView) findViewById(R.id.activity_main_rssi_textview);
WifiManager wifiManager = (WifiManager) WiFiActivity.this.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifiManager.getConnectionInfo();
ssidTextView.setText("SSID/网络的名称: " + info.getSSID());
bssidTextView.setText("BSSID/接入点地址: " + info.getBSSID());
macTextView.setText("MAC: " + info.getMacAddress());
linkSpeedTextView.setText("Link Speed: " + info.getLinkSpeed());
rssiTextView.setText("Rssi/无线网络的接收信号强度: " + info.getRssi());
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wifi);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(123);
}
}, 0, 1000);
}
}
布局文件就不贴上来了,大家根据自己需要添加咯,也不要问,要这些参数可以干什么,等到你用到时就知道了