瀏覽代碼

anr错误不上传日志,只保存在本地,然后重启app

weizhengliang 3 年之前
父節點
當前提交
c872a53f3f
共有 1 個文件被更改,包括 32 次插入1 次删除
  1. 32 1
      nursehome/src/main/java/com/wdkl/ncs/android/component/nursehome/util/XCrashUtils.java

+ 32 - 1
nursehome/src/main/java/com/wdkl/ncs/android/component/nursehome/util/XCrashUtils.java

@@ -78,6 +78,37 @@ public class XCrashUtils {
         }
     };
 
+    // callback for  ANR
+    private final ICrashCallback anrCallback = new ICrashCallback() {
+        @Override
+        public void onCrash(String logPath, String emergency) {
+            Log.d(TAG, "log path: " + (logPath != null ? logPath : "(null)") + ", emergency: " + (emergency != null ? emergency : "(null)"));
+
+            if (emergency != null) {
+                debug(logPath, emergency);
+
+                // Disk is exhausted, send crash report immediately.
+                //sendThenDeleteCrashLog(logPath, emergency);
+            } else {
+                // Add some expanded sections. Send crash report at the next time APP startup.
+
+                // OK
+                TombstoneManager.appendSection(logPath, "expanded_key_1", "expanded_content");
+                TombstoneManager.appendSection(logPath, "expanded_key_2", "expanded_content_row_1\nexpanded_content_row_2");
+
+                // Invalid. (Do NOT include multiple consecutive newline characters ("\n\n") in the content string.)
+                // TombstoneManager.appendSection(logPath, "expanded_key_3", "expanded_content_row_1\n\nexpanded_content_row_2");
+
+                debug(logPath, null);
+            }
+
+            // Disk is exhausted, send crash report immediately.
+            //sendThenDeleteCrashLog(logPath, emergency);
+
+            AppUtils.relaunchApp(true);
+        }
+    };
+
     public void init(Application application) {
         Log.d(TAG, "xCrash SDK init: start");
         app = application;
@@ -97,7 +128,7 @@ public class XCrashUtils {
                 .setNativeCallback(callback)
                 .setAnrRethrow(true)
                 .setAnrLogCountMax(10)
-                .setAnrCallback(callback)
+                .setAnrCallback(anrCallback)
                 .setPlaceholderCountMax(3)
                 .setPlaceholderSizeKb(512)
                 .setLogDir(application.getExternalFilesDir("xcrash").toString())