Android常用代码-bugly集成

  1. 1. 集成bugly
  2. 2. 添加权限
  3. 3. Application的onCreate方法中初始化
    1. 3.1. 不带X5内核
    2. 3.2. 带X5内核

集成bugly

1
2
//bugly
compile 'com.tencent.bugly:crashreport:latest.release'

添加权限

1
2
3
<!-- bugly start-->
<uses-permission android:name="android.permission.READ_LOGS" />
<!--bugly end-->

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
/*bugly+x5内核*/
try {
CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(this);
strategy.setCrashHandleCallback(new CrashReport.CrashHandleCallback() {
public Map onCrashHandleStart(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;
}

@Override
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();
}