App.java
1.76 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
package com.sunvote.xpadapp;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.Application;
import android.content.Context;
import com.sunvote.xpadcomm.XPadApi;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import java.util.List;
public class App extends Application {
public static XPadApi XPad;
@Override
public void onCreate() {
XPad = XPadApi.getInstance();
// XPad.getClient().disableLogtoFile();
// XPad.getClient().disableModuleLog();
ZXingLibrary.initDisplayOpinion(this);
final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
if (uncaughtExceptionHandler != null) {
uncaughtExceptionHandler.uncaughtException(thread, ex);
}
System.exit(0);
}
});
super.onCreate();
}
public static boolean isBackground(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
for (RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.processName.equals(context.getPackageName())) {
if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
return true;
} else {
return false;
}
}
}
return false;
}
}