android常用代码-bugly集成

集成bugly

1
2
//bugly
implementation 'com.tencent.bugly:crashreport:2.6.6'

Application的onCreate方法中初始化

不带X5内核

1
2
3
4
5
try {
CrashReport.initCrashReport(this, "你的appID", false);
} catch (Exception e) {
e.printStackTrace();
}

带X5内核

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
try {
CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(this);
strategy.setCrashHandleCallback(new CrashReport.CrashHandleCallback() {
public Map (int crashType, String errorType, String errorMessage, String errorStack) {
LinkedHashMap map = new LinkedHashMap();
String x5CrashInfo = com.tencent.smtt.sdk.WebView.getCrashExtraMessage(GFApplication.this);
map.put("x5crashInfo", x5CrashInfo);
return map;
}
public byte[] onCrashHandleStart2GetExtraDatas(int crashType, String errorType, String errorMessage, String errorStack) {
try {
return "Extra data.".getBytes("UTF-8");
} catch (Exception e) {
return null;
}
}
});
CrashReport.initCrashReport(this, "你的appID", false, strategy);
} catch (Exception e) {
e.printStackTrace();
}