Android 全局捕获异常+腾讯bugly
总体步骤按照腾讯bugly文档
一、导入所需要的依赖
implementation 'com.tencent.bugly:crashreport:latest.release'
二 、权限
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" tools:ignore="ProtectedPermissions" />
三、在“AndroidManifest.xml”的“Application”中增加“meta-data”配置项
<meta-data android:name="BUGLY_APPID" android:value="看下面图片" />
<!-- 配置APP版本号 --><meta-data android:name="BUGLY_APP_VERSION" android:value="当前App版本号" />
腾讯bugly链接 需登入
对应上面AppID四、implements Thread.UncaughtExceptionHandler
可复制代码在下边
代码在下↓public class ExceptionAppliction implements Thread.UncaughtExceptionHandler {private static final String TAG = "ExceptionAppliction"; //单例 private static ExceptionAppliction exceptionAppliction; private ExceptionAppliction(){} public static ExceptionAppliction getExceptionAppliction(){ if (exceptionAppliction == null) { exceptionAppliction = new ExceptionAppliction(); } Thread.setDefaultUncaughtExceptionHandler(exceptionAppliction); return exceptionAppliction; } @Override public void uncaughtException(Thread t,Throwable e) { String model = Build.MODEL; //模型 String brand = Build.BRAND; //手机品牌 int sdkInt = Build.VERSION.SDK_INT; //版本 Log.i(TAG, "uncaughtException: "+model); Log.i(TAG, "uncaughtException: "+brand); Log.i(TAG, "uncaughtException: "+sdkInt); //退出app Process.killProcess(Process.myPid()); }}
咱也不知道这文本为啥不智能换行
五、Application
Application调用 否则不生效ExceptionAppliction.getExceptionAppliction();
CrashReport.initCrashReport(getApplicationContext());
最后最后的最后
自己整个错误 玩一玩
仅供半杯水程序员观看 大佬勿喷