Android 捕获异常,上报异常日志,捕获奔溃日志,bugly使用实例
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Android 捕获异常,上报异常日志,捕获奔溃日志,bugly使用实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                1、登錄騰訊bugly平臺創建應用
?騰訊Bugly - 一種愉悅的開發方式 _android anr_android anr分析_iOS崩潰日志分析平臺
2、1加載依賴
/*崩潰處理 */ implementation 'com.tonystark.android:defense_crash:2.0.0' //bugly implementation 'com.tencent.bugly:crashreport_upgrade:1.3.5'implementation'com.tencent.bugly:nativecrashreport:3.3.1'2、2添加maven
maven { url 'https://dl.bintray.com/xuuhaoo/maven/' }3、工具類
public class ForReportException extends Exception {public ForReportException() {}public ForReportException(String msg) {super(msg);}public ForReportException(String msg, Throwable throwable) {super(msg, throwable);} }4、實現捕獲異常上報代碼?
public class App extends Application implements IExceptionHandler { ? initBugly(); }private void initBugly() {CrashReport.initCrashReport(getApplicationContext(), "c50f1d7329", BuildConfig.DEBUG); } @Override protected void attachBaseContext(Context base) {super.attachBaseContext(base);/**///MultiDex.install(this);// step1: Initialize the lib.DefenseCrash.initialize();// step2: Install the fire wall defense.DefenseCrash.install(this); }@Override public void onCaughtException(Thread thread, Throwable throwable, boolean b) {throwable.printStackTrace();/*todo 收集系統信息*//*todo 發送郵件*//*bugly 手動上報異常*/CrashReport.postCatchedException(throwable); }@Override public void onEnterSafeMode() {LogPlus.d("###########onEnterSafeMode###########"); }@Override public void onMayBeBlackScreen(Throwable throwable) {/*重啟app*/Thread thread = Looper.getMainLooper().getThread();CrashReport.postCatchedException(new ForReportException("onMayBeBlackScreen", throwable));restartApp(); }/*** 重啟app*/ public void restartApp() {Intent mStartActivity = new Intent(this, MainActivity.class);int mPendingIntentId = 123456;PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);System.exit(0); }主動拋出異常?
throw new IllegalStateException("setDefaultFrameFormat should be call before initMonitor");?5、登錄bugly平臺即可查看到所有APP的異常日志,定位去解決效果
String sendstring = stringBuffer.toString();Throwable throwable = new Throwable(sendstring);CrashReport.postCatchedException(throwable);//上報到bugly?
@Override public void onCaughtException(Thread thread, Throwable throwable, boolean b) {CrashReport.postCatchedException(throwable); }@Override public void onEnterSafeMode() {}@Override public void onMayBeBlackScreen(Throwable throwable) {CrashReport.postCatchedException(throwable);/*重啟APP*/restartApp(); }/*** 重啟app*/ public void restartApp() {Intent mStartActivity = new Intent(this, SplashScreenActivity.class);int mPendingIntentId = 123456;PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);System.exit(0); }?實現demo:android開發,異常處理,捕獲異常上傳到bugly,捕獲異常庫module-Android文檔類資源-CSDN下載
bug交流:QQ? 1085220040
總結
以上是生活随笔為你收集整理的Android 捕获异常,上报异常日志,捕获奔溃日志,bugly使用实例的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 6.8
- 下一篇: linux 微信机器人,开源Linux操
