日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android 捕获异常,上报异常日志,捕获奔溃日志,bugly使用实例

發(fā)布時(shí)間:2023/12/10 Android 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 捕获异常,上报异常日志,捕获奔溃日志,bugly使用实例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、登錄騰訊bugly平臺(tái)創(chuàng)建應(yīng)用

?騰訊Bugly - 一種愉悅的開(kāi)發(fā)方式 _android anr_android anr分析_iOS崩潰日志分析平臺(tái)

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、實(shí)現(xiàn)捕獲異常上報(bào)代碼?

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 收集系統(tǒng)信息*//*todo 發(fā)送郵件*//*bugly 手動(dòng)上報(bào)異常*/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); }

主動(dòng)拋出異常?

throw new IllegalStateException("setDefaultFrameFormat should be call before initMonitor");

?5、登錄bugly平臺(tái)即可查看到所有APP的異常日志,定位去解決效果

String sendstring = stringBuffer.toString();Throwable throwable = new Throwable(sendstring);CrashReport.postCatchedException(throwable);//上報(bào)到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); }

?實(shí)現(xiàn)demo:android開(kāi)發(fā),異常處理,捕獲異常上傳到bugly,捕獲異常庫(kù)module-Android文檔類資源-CSDN下載

bug交流:QQ? 1085220040

總結(jié)

以上是生活随笔為你收集整理的Android 捕获异常,上报异常日志,捕获奔溃日志,bugly使用实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。