Blame view

C5/app/src/main/java/com/sunvote/xpadapp/App.java 2.24 KB
fac86401   孙向锦   初始化C5 Vote
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
  package com.sunvote.xpadapp;
  
  import android.app.ActivityManager;
  import android.app.ActivityManager.RunningAppProcessInfo;
  import android.app.Application;
  import android.content.Context;
  
  import com.sunvote.udptransfer.UDPModule;
  import com.sunvote.udptransfer.work.BaseStationProcessWork;
  import com.sunvote.util.LogUtil;
  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() {
          BaseStationProcessWork.getInstance().setContext(this);
          XPad = XPadApi.getInstance();
  //        XPad.getClient().disableLogtoFile();
  //        XPad.getClient().disableModuleLog();
          XPad.getClient().enablelogtoFile();
          XPad.getClient().enableModuleLog();
          XPad.getClient().setContext(this);
          ZXingLibrary.initDisplayOpinion(this);
          final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
          Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
              @Override
              public void uncaughtException(Thread thread, Throwable ex) {
                  LogUtil.e(UDPModule.TAG, "carsh(thread id:" + thread.getId() + ",thread name:" + thread.getName() + ")");
                  LogUtil.e(UDPModule.TAG, 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;
      }
  }