File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
pandora-core/src/main/java/tech/linjiang/pandora Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 22
33import android .app .Activity ;
44import android .app .Application ;
5+ import android .content .Context ;
56import android .support .v4 .content .FileProvider ;
67
78import tech .linjiang .pandora .crash .CrashHandler ;
@@ -30,7 +31,8 @@ public Pandora() {
3031 @ Override
3132 public boolean onCreate () {
3233 INSTANCE = this ;
33- init (((Application ) getContext ()));
34+ Context context = Utils .makeContextSafe (getContext ());
35+ init (((Application ) context ));
3436 return super .onCreate ();
3537 }
3638
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ public Response intercept(Chain chain) throws IOException {
6262 Response response ;
6363 try {
6464 response = chain .proceed (request );
65- } catch (IOException e ) {
65+ } catch (Throwable e ) {
6666 if (Config .isNetLogEnable () && id >= 0 ) {
6767 markFailed (id , Utils .collectThrow (e ));
6868 notifyEnd (id );
Original file line number Diff line number Diff line change 2121import java .io .PrintWriter ;
2222import java .io .StringWriter ;
2323import java .io .Writer ;
24+ import java .lang .reflect .Method ;
2425import java .math .BigDecimal ;
2526import java .text .DateFormat ;
2627import java .text .SimpleDateFormat ;
@@ -229,4 +230,18 @@ public static String collectThrow(Throwable ex) {
229230 printWriter .close ();
230231 return writer .toString ();
231232 }
233+
234+ public static Context makeContextSafe (Context context ) {
235+ if (context != null ) {
236+ return context ;
237+ }
238+ try {
239+ Class actThreadClass = Reflect28Util .forName ("android.app.ActivityThread" );
240+ Method method = Reflect28Util .getDeclaredMethod (actThreadClass , "currentApplication" );
241+ return (Context ) method .invoke (null );
242+ } catch (Exception e ) {
243+ e .printStackTrace ();
244+ return null ;
245+ }
246+ }
232247}
You can’t perform that action at this time.
0 commit comments