腾讯bugly简单使用

第一步腾讯bugly官网中创建应用拿到APPID

导依赖(看清在哪个标签下)

android {
    defaultConfig {
        ndk {
            // 设置支持的SO库架构
            abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
        }
    }
}

dependencies {
    compile 'com.tencent.bugly:crashreport:latest.release' //其中latest.release指代最新Bugly SDK版本号,也可以指定明确的版本号,例如2.1.9
    compile 'com.tencent.bugly:nativecrashreport:latest.release' //其中latest.release指代最新Bugly NDK版本号,也可以指定明确的版本号,例如3.0
}

在AndroidManifest.xml中添加权限:

<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" />

再创建两个类

*Time:2019/3/28
 *Author:zhaozhiwei
 *Description:
 */public class IMApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        MyUnCatchExceptionHandler.getInstance().init(this);
        //第一个参数上下文,再后是注册时申请的APPID
        CrashReport.initCrashReport(this,"9d453034c2",false);

    }

}

另一个

/*Time:2019/3/28
 *Author:zhaozhiwei
 *Description:
 */public class MyUnCatchExceptionHandler implements Thread.UncaughtExceptionHandler {
     private static MyUnCatchExceptionHandler instance;
     private Context context;
     private Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler;

     public static MyUnCatchExceptionHandler getInstance(){
         if (instance==null){
             instance=new MyUnCatchExceptionHandler();
         }
         return instance;
     }

     public void init(Context context){
         this.context= context;
         defaultUncaughtExceptionHandler=Thread.getDefaultUncaughtExceptionHandler();
         Thread.setDefaultUncaughtExceptionHandler(this);
     }

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        // TODO: 2019/3/28  收集异常信息
        /**
         * 异常类型
         * 异常时间
         * 手机型号
         * 手机品牌
         * 系统版本
         * 。。。。
         */
        // TODO: 2019/3/28 上传服务器
        //如果系统提供了处理器,那么交给系统处理
         if (defaultUncaughtExceptionHandler!=null){
             defaultUncaughtExceptionHandler.uncaughtException(t,e);
         }else {
             //如果我们自己处理,一般来讲,直接杀死进程即可
             android.os.Process.killProcess(android.os.Process.myPid());
         }
    }
}

在清单文件中注册活动

 android:name=".IMApp"

异常便可以在腾讯bugly中呈现了

更详细全面截官方教程Bugly Android SDK 使用指南

猜你喜欢

转载自blog.csdn.net/Android_Mr_Zhao/article/details/88869286
今日推荐