33import android .app .Activity ;
44import android .app .Application ;
55import android .content .Context ;
6- import android .content .pm .ApplicationInfo ;
7- import android .content .pm .PackageManager ;
86import android .util .Log ;
97
10- import com .guiying .common .utils .StringUtils ;
118import com .guiying .common .utils .Utils ;
129import com .orhanobut .logger .LogLevel ;
1310import com .orhanobut .logger .Logger ;
1916 * 组件中实现的Application必须在AndroidManifest.xml中注册,否则无法使用;
2017 * 组件的Application需置于java/debug文件夹中,不得放于主代码;
2118 * 组件中获取Context的方法必须为:Utils.getContext(),不允许其他写法;
22- * BaseApplication主要有如下功能:
23- * 1、全局获取Context;
24- * 2、用来管理全局Activity;
19+ * BaseApplication主要用来管理全局Activity;
2520 *
2621 * @author 2016/12/2 17:02
2722 * @version V1.0.0
@@ -41,9 +36,8 @@ public static BaseApplication getIns() {
4136 public void onCreate () {
4237 super .onCreate ();
4338 sInstance = this ;
44- Context context = this .getApplicationContext ();
45- Utils .init (context );
46- if (isAppDebug (context )) {
39+ Utils .init (this );
40+ if (Utils .isAppDebug ()) {
4741 //只有debug模式才会打印日志
4842 Logger .init ("Petrel" ).logLevel (LogLevel .FULL );
4943 } else {
@@ -125,22 +119,5 @@ public void exitApp(Context context) {
125119 }
126120 }
127121
128- /**
129- * 判断App是否是Debug版本
130- *
131- * @param context 上下文
132- * @return {@code true}: 是<br>{@code false}: 否
133- */
134- public static boolean isAppDebug (Context context ) {
135- if (StringUtils .isSpace (context .getPackageName ())) return false ;
136- try {
137- PackageManager pm = context .getPackageManager ();
138- ApplicationInfo ai = pm .getApplicationInfo (context .getPackageName (), 0 );
139- return ai != null && (ai .flags & ApplicationInfo .FLAG_DEBUGGABLE ) != 0 ;
140- } catch (PackageManager .NameNotFoundException e ) {
141- e .printStackTrace ();
142- return false ;
143- }
144- }
145122
146123}
0 commit comments