-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookbookApp.java
More file actions
164 lines (137 loc) · 4.48 KB
/
BookbookApp.java
File metadata and controls
164 lines (137 loc) · 4.48 KB
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
package com.android.bookbook;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import com.android.bookbook.util.HttpUtil;
import com.android.bookbook.util.PicUtil;
import com.android.bookbook.util.SharedPreferencesUtil;
import android.app.Application;
import android.app.NotificationManager;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Build;
import android.telephony.TelephonyManager;
public class BookbookApp extends Application {
// 手机信息
public String app;
public String device;
public String macId;
public String ver;
public String finalVer;
public String mobile;
public String system;
public String description;
public String myIMSI;
public int versionCode;
public String promotion = "b00";// 渠道编号
private final int NOTIC_ID = 123;
public String title;
public String message;
public String uMeng;
public String networkTypeString;
private static BookbookApp _instance;
private NotificationManager notificationManager;
public SharedPreferencesUtil sharedPreferencesUtil;
public static BookbookApp getInstance() {
if (_instance == null) {
_instance = new BookbookApp();
}
return _instance;
}
@Override
public void onCreate() {
super.onCreate();
_instance = this;
if (notificationManager != null) {
notificationManager.cancel(NOTIC_ID);
}
//initUtil();// 初始化工具类
//initOtherVars();// 初始化一般变量
//new InitDatasInThread().execute();
}
private void initUtil() {
sharedPreferencesUtil = new SharedPreferencesUtil();
/* DbUtil.initialize();
HaozuApiUtil.initialize();*/
HttpUtil.initialize();
PicUtil.initialize();
}
private class InitDatasInThread extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if (!sharedPreferencesUtil.getString("firstTime").equals("firstTime")) {
// 从assets文件中写回sharedPerference
sharedPreferencesUtil.saveBoolean("cityListDataFileIsAvaliable", true);
sharedPreferencesUtil.saveString("firstTime", "firstTime");
}
return null;
}
}
private void initOtherVars() {
// DEBUG = MapViewUtilsBaidu.isDebugBuild(this);
BookbookApp.getInstance().app = "BookBook";
BookbookApp.getInstance().mobile = "Android-" + URLEncoder.encode(android.os.Build.MODEL);
BookbookApp.getInstance().system = URLEncoder.encode(android.os.Build.VERSION.RELEASE);
BookbookApp.getInstance().description = URLEncoder.encode(getBuildDescription());
PackageManager manager = getPackageManager();
PackageInfo info = null;
try {
info = manager.getPackageInfo(getPackageName(), 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
BookbookApp.getInstance().ver = URLEncoder.encode(info.versionName);
BookbookApp.getInstance().versionCode = info.versionCode;
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
BookbookApp.getInstance().myIMSI = mTelephonyMgr.getSubscriberId();
BookbookApp.getInstance().device = mTelephonyMgr.getDeviceId();
BookbookApp.getInstance().macId = getLocalMacAddress();
}
public String getLocalMacAddress() {
WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE);
if (wifi == null) {
return "";
}
WifiInfo info = wifi.getConnectionInfo();
if (info == null) {
return "";
}
return info.getMacAddress();
}
public void setLastmodifyTime(String time) {
sharedPreferencesUtil.saveString("lastModifyTime", time);
}
public String getLastModifyTime() {
String lastModifyTime = sharedPreferencesUtil.getString("lastModifyTime");
if (lastModifyTime == null || lastModifyTime.length() == 0) {
return String.valueOf(0);
}
return lastModifyTime;
}
private String getBuildDescription() {
String desc = "unknown";
try {
Class<?> clazz = Class.forName("android.os.Build");
Class<?> paraTypes = Class.forName("java.lang.String");
Method method = clazz.getDeclaredMethod("getString", paraTypes);
if (!method.isAccessible()) {
method.setAccessible(true);
}
Build b = new Build();
desc = (String) method.invoke(b, "ro.build.description");
} catch (Exception e) {
e.printStackTrace();
}
return desc;
}
public void setVersion(String verName){
this.ver = verName;
}
public void setDefaultVersion(){
this.ver = finalVer;
}
}