1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package jp.co.sumoretece.android.mobileinfo;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
public class InfoCollection extends Activity {
private static StringBuffer buffer;
TextView infos;
TextView title;
List list2;
List list3;
List list4;
protected Menu myMenu;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showinfo);
refreshListItems();
}
private void refreshListItems() {
infos = (TextView) findViewById(R.id.info);
title = (TextView) findViewById(R.id.title);
title.setText("查看信息");
TextView blight = (TextView) findViewById(R.id.blight);
float light = getOldBrightness();
blight.setText("/n======/nbrightness:" + light);
String i = getTelephonyManager(this);
String tel = i;
String ii = getActivityManager();
String aam = ii;
String iii = getCpu();
String cpu = iii + "/n======/n";
String wifi = getWifiInfo();
String si = getNetWorkIP();
String network = si + "/n======/n";
boolean ss = isConnected();
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText("/n======/nisConnected():" + ss + "/n");
infos.setText(tel.toString() + aam.toString() + wifi.toString() + network.toString() + cpu.toString());
}
/**
* 获取TelephonyManager
*
*/
public static String getTelephonyManager(Context cx) {
String result = null;
TelephonyManager tm = (TelephonyManager) cx.getSystemService(Context.TELEPHONY_SERVICE);
String str = "/n======/nTelephonyManager/n";
str += "getDataState() = " + tm.getDataState() + "/n";
str += "getDeviceId() = " + tm.getDeviceId() + "/n";
str += "getLine1Number() = " + tm.getLine1Number() + "/n";
str += "getSimSerialNumber() = " + tm.getSimSerialNumber() + "/n";
str += "getSubscriberId() = " + tm.getSubscriberId() + "/n";
str += "isNetworkRoaming() = " + tm.isNetworkRoaming() + "/n";
result = str.toString();
return result;
}
/**
* 获取获取Wifi
*
*/
public String getWifiInfo() {
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
String s1 = "/n======/nWifiState:/nWIFI_STATE_UNKNOWN/n";
String s21 = "/n======/nWifiState:/nWIFI_STATE_KNOWN/n";
StringBuilder stringbuilder = new StringBuilder("/nState:");
if (wifiManager.getWifiState() != 3) {
String s2 = s1;
String s3 = stringbuilder.append(s2).toString();
String s4 = s3;
return s4;
}
else {
return s21.toString();
}
}
/**
* 获取ActivityManager
*
*/
public String getActivityManager() {
String result = null;
StringBuffer str = new StringBuffer("/n======/nActivityManager/n");
ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List list1 = activityManager.getRunningAppProcesses();
for (int i = 0; i < list1.size(); i++) {
String b = list1.get(i).toString();
str.append(b + "/n");
}
return str.toString();
}
/**
* 获取当前亮度值
*
*/
private float getOldBrightness() {
float brightness;
try {
brightness = Settings.System.getInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS);
}
catch (SettingNotFoundException snfe) {
brightness = 255;
}
return brightness;
}
/**
* 获取Cpu
*
*/
private String getCpu() {
ProcessBuilder cmd;
String result = "";
try {
String[] args = { "/system/bin/cat", "/proc/cpuinfo" };
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while (in.read(re) != -1) {
System.out.println(new String(re));
result = result + new String(re);
return result.toString();
}
in.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
return result.toString();
}
/**
* 获取NetWorkIP
*
*/
public static String getNetWorkIP() {
String result = "/n======/n";
CMDExecute cmdexe = new CMDExecute();
try {
String[] args = { "/system/bin/netcfg" };
result = cmdexe.run(args, "/system/bin/");
}
catch (IOException ex) {
Log.i("fetch_process_info", "ex=" + ex.toString());
}
return result;
}
/**
* 获取isConnected()
*
*/
public boolean isConnected() {
ConnectivityManager mConnectivity = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager mTelephony = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
// 检查网络连接,如果无网络可用,就不需要进行连网操作等
NetworkInfo info = mConnectivity.getActiveNetworkInfo();
if (info == null || !mConnectivity.getBackgroundDataSetting()) {
return false;
} // 判断网络连接类型,只有在3G或wifi里进行一些数据更新。
int netType = info.getType();
int netSubtype = info.getSubtype();
if (netType == ConnectivityManager.TYPE_WIFI) {
return info.isConnected();
}
else if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS && !mTelephony.isNetworkRoaming()) {
return info.isConnected();
}
else {
return false;
}
}
}