AppCenter+AppInsights在Android崩溃时没有提供详细错误报告。
创始人
2024-09-10 00:00:46
0

在使用App Center + App Insights时,可以使用以下代码来捕获Android上的崩溃信息并将其发送到App Center:

public class MyApplication extends Application implements AppCenterHandler {

    @Override
    public void onCreate() {
        super.onCreate();

        // Initialize App Center
        AppCenter.start(this, "YOUR_APP_SECRET", Analytics.class, Crashes.class);

        // Set the handler for uncaught exceptions
        Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
    }

    // App Center handler callback
    @Override
    public boolean shouldProcess(final AppCenterLog appCenterLog) {
        return true;
    }

    // App Center handler callback
    @Override
    public void onBeforeSending(final Log log) {
        if (log instanceof ErrorLog) {
            // This log is an error log
            final ErrorLog errorLog = (ErrorLog) log;

            // Access the throwable (i.e. the exception) that was caught
            final Throwable throwable = errorLog.getThrowable();

            // Log the stack trace for debugging
            Log.e(getClass().getSimpleName(), "Error log stack trace:", throwable);
        }
    }

    // Custom uncaught exception handler
    private static class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {

        // Called when an uncaught exception occurs
        @Override
        public void uncaughtException(final Thread thread, final Throwable throwable) {
            Crashes.trackError(throwable);
        }
    }
}

这个解决方法创建了一个自定义的Application类,它实现了App Center的回调接口AppCenterHandler。在onCreate方法中,我们初始化了App Center并设置了一个自定义的UncaughtExceptionHandler,当一个未捕获的异常发生时,它将被发送到App Center。在shouldProcess回调中,我们返回true,表示我们希望处理所有的App Center日志。在onBeforeSending回调中,我们检查日志是否是一个ErrorLog,如果是,我们记录堆栈跟踪信息。最后,在自定义的UncaughtExceptionHandler中,我们使用Crashes.track

相关内容

热门资讯

推荐一款!广东雀神智能插件免费... 推荐一款!广东雀神智能插件免费,四川熊猫辅助,详细软件(有挂规律);运广东雀神智能插件免费辅助工具,...
攻略讲解!蜀山四川游戏修改工具... 攻略讲解!蜀山四川游戏修改工具,多乐辅助下载,详细神器(有挂秘诀)1、蜀山四川游戏修改工具公共底牌简...
推荐十款!湖北卡五星如啊你就按... 推荐十款!湖北卡五星如啊你就按,潮友潮汕木虱开挂辅助器下载,详细器(有挂工具)1、打开软件启动之后找...
玩家必看秘籍!大巴杭州辅助,新... 玩家必看秘籍!大巴杭州辅助,新畅游互娱辅助app,详细神器(有挂教学)1、新畅游互娱辅助app公共底...
玩家必备攻略!拱趴大菠萝辅助神... 玩家必备攻略!拱趴大菠萝辅助神器,雀友会广东潮汕辅助有开挂,详细神器(有挂细节)一、雀友会广东潮汕辅...
推荐一款!微乐贵阳捉鸡麻将能不... 推荐一款!微乐贵阳捉鸡麻将能不能开挂,微乐小程序辅助开发透视,详细攻略(有挂详情)亲,关键说明,微乐...
玩家亲测!贪玩娱乐科技,腾威互... 玩家亲测!贪玩娱乐科技,腾威互娱破解辅助工具,详细软件(有挂实锤)运腾威互娱破解辅助工具辅助工具,进...
一分钟揭秘!广东闲来辅助神器免... 一分钟揭秘!广东闲来辅助神器免费版,九九联盟辅助,详细器(有挂分享)1)广东闲来辅助神器免费版有没有...
大神推荐!欢乐对决辅助软件,微... 大神推荐!欢乐对决辅助软件,微信小程序万能修改器,详细脚本(有挂细节)运微信小程序万能修改器辅助工具...
玩家必看科普!人海大厅挂什么好... 玩家必看科普!人海大厅挂什么好,创思维激k透视插件,详细工具(有挂头条)1、打开软件启动之后找到中间...