为了将未捕获的异常的堆栈跟踪信息包含到Google Analytics(分析)中,我将默认的ExceptionParser替换为自定义的ExceptionParser.
现在,我获得了带有stackstrace的异常的另一个报表,该报表具有不带stacktrace的异常(默认值).我究竟做错了什么?
public class AnalyticsHelper{ /** * This method is called in my Application#onCreate(..) **/ public static voID initAnalytics(Context c) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(c); analytics.setAppOptOut(PreferenceManager.getDefaultSharedPreferences(c).getBoolean(PreferencesActivity.KEY_ANAYLTICS_OPT_OUT, false)); // setting uncaught exception handler ExceptionReporter reporter = new ExceptionReporter(analytics.getInstance(c).newTracker(R.xml.tracker), Thread.getDefaultUncaughtExceptionHandler(), c); reporter.setExceptionParser(new ExceptionParser() { @OverrIDe public String getDescription(String p_thread, Throwable throwable) { StringWriter trace = new StringWriter(); throwable.printstacktrace(new PrintWriter(trace)); String stacktrace = trace.toString(); String message = (throwable.getMessage() == null) ? "no message" : throwable.getMessage(); return "Message: " + message + ", Stacktrace: " + stacktrace; } }); Thread.setDefaultUncaughtExceptionHandler(reporter); }}
tracker.xml
<?xml version="1.0" enCoding="utf-8"?><resources xmlns:tools="http://schemas.androID.com/tools" tools:ignore="TypographyDashes"> <integer name="ga_sessionTimeout">300</integer> <bool name="ga_reportUncaughtExceptions">true</bool> <bool name="ga_autoActivityTracking">false</bool> <integer name="ga_dispatchPeriod">5</integer> <string name="ga_trackingID">XXXXXX</string></resources>
解决方法:
从Google Analytics document:
To automatically send all uncaught exceptions in your app using EasyTracker, add this line to your analytics.xml file:
<bool name="ga_reportUncaughtExceptions">true</bool>
After sending an exception using automatic exception measurement, EasyTracker will pass the exception on to the Thread’s default exception handler.
通过将ga_reportUncaughtExceptions设置为true,跟踪程序将自动发送异常,因此您获得了一份额外的报告,而没有stacktrace.删除它,您将只获得一份报告.
总结以上是内存溢出为你收集整理的android-Google Analytics(分析)两次发送未捕获的异常全部内容,希望文章能够帮你解决android-Google Analytics(分析)两次发送未捕获的异常所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)