-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyApplication.java
More file actions
94 lines (78 loc) · 2.43 KB
/
Copy pathMyApplication.java
File metadata and controls
94 lines (78 loc) · 2.43 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
package rayfantasy.icode;
import android.app.*;
import android.content.*;
import android.net.*;
import android.preference.*;
import android.telephony.*;
import android.widget.*;
import cn.bmob.v3.*;
import cn.bmob.v3.listener.*;
import rayfantasy.icode.Bmob.*;
public class MyApplication extends Application
{
private SharedPreferences setting;
private Context context;
public static final String Bmob_APPID="ed40b22516d8679a79eca831e77ec5ad";
public void onCreate() {
super.onCreate();
setting = PreferenceManager.getDefaultSharedPreferences(this);
Bmob.initialize(this, Bmob_APPID);
context=this;
}
public void editString(String s, String message) {
setting.edit().putString(s, message).apply();
}
public void editBoolean(String s, boolean message) {
setting.edit().putBoolean(s, message).apply();
}
public void editint(String s, int message) {
setting.edit().putInt(s, message).apply();
}
public int getint(String s, int message) {
return setting.getInt(s, message);
}
public boolean getBoolean(String s, boolean message) {
return setting.getBoolean(s, message);
}
public String getString(String s, String message) {
return setting.getString(s, message);
}
public void showToast(String s) {
Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
}
public String getImei(){
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
return tm.getDeviceId();
}
//判断网络状态
public static boolean detect(Activity act) {
ConnectivityManager manager = (ConnectivityManager) act
.getApplicationContext().getSystemService(
Context.CONNECTIVITY_SERVICE);
if (manager == null) {
return false;
}
NetworkInfo networkinfo = manager.getActiveNetworkInfo();
if (networkinfo == null || !networkinfo.isAvailable()) {
return false;
}
return true;
}
//上传数据Title为标题,Message为内容,User为用户名
public void saveData(String Title,String Message,String User){
Data bmobdata = new Data();
bmobdata.setTitle(Title);
bmobdata.setMessage(Message);
bmobdata.setUser(User);
bmobdata.save(this, new SaveListener() {
@Override
public void onSuccess() {
showToast("上传代码成功!");
}
@Override
public void onFailure(int code, String arg0) {
showToast("上传代码失败:"+arg0);
}
});
}
}