Just add this to your manifest
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/tracker.xml" />
After that, you should start getting in this logcat:
V/GAV4﹕ Thread[main,5,main]: Tracking Exception: ArithmeticException (@MyActivity:onResume:111) {main} V/GAV4﹕ Thread[main,5,main]: Dispatch call queued. Dispatch will run once initialization is complete. V/GAV4﹕ Thread[main,5,main]: Passing exception to original handler.
After restarting the application:
V/GAV4﹕ Thread[client_id_fetcher,5,main]: Loaded client id from disk. V/GAV4﹕ Thread[main,5,main]: Loading Tracker config values. V/GAV4﹕ Thread[main,5,main]: [Tracker] trackingId loaded: UA-XXXXXXXX-X V/GAV4﹕ Thread[main,5,main]: [Tracker] session timeout loaded: 300000 V/GAV4﹕ Thread[main,5,main]: ExceptionReporter created, original handler is com.android.internal.os.RuntimeInit$UncaughtHandler V/GAV4﹕ Thread[main,5,main]: Uncaught exceptions will be reported to Google Analytics. V/GAV4﹕ Thread[GAThread,5,main]: connecting to Analytics service V/GAV4﹕ Thread[main,5,main]: service connected, binder: android.os.BinderProxy@42175d30 V/GAV4﹕ Thread[main,5,main]: bound to service V/GAV4﹕ Thread[GAThread,5,main]: connect: bindService returned true for Intent { act=com.google.android.gms.analytics.service.START cmp=com.google.android.gms/.analytics.service.AnalyticsService (has extras) } V/GAV4﹕ Thread[main,5,main]: Connected to service I/GAV4﹕ Thread[GAThread,5,main]: No campaign data found. V/GAV4﹕ Thread[GAThread,5,main]: Initialized GA Thread V/GAV4﹕ Thread[GAThread,5,main]: Loaded clientId V/GAV4﹕ Thread[GAThread,5,main]: Loaded clientId V/GAV4﹕ Thread[GAThread,5,main]: putHit called V/GAV4﹕ Thread[GAThread,5,main]: Sending hit to service PATH: https: PARAMS: ul=en-us, ht=1408554996959, sr=720x1184, a=194292074, aid=<app package>, cid=9639b81c-b17a-4c3a-a43e-0c1f43a6d5c1, av=1.5.0.1, v=1, t=exception, an=<app name>, tid=UA-XXXXXXXX-X, exd=SQLiteBindOrColumnIndexOutOfRangeException (@MyApp:onCreate:185) {main}, _u=.nKhAAAL, exf=0
I am currently using this code in my project (in the Application.onCreate () method), it works fine:
GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(this); applicationPreferences = new ApplicationPreferences(getApplicationContext()); tracker = googleAnalytics.newTracker(R.xml.tracker); tracker.enableExceptionReporting(true); String lastErrorString = applicationPreferences.getLastErrorString(); if (lastErrorString != null) { applicationPreferences.clearLastErrorString(); tracker.send(new HitBuilders.ExceptionBuilder().setDescription(lastErrorString).setFatal(true).build()); } final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable throwable) { applicationPreferences.setLastErrorString(Throwables.getStackTraceAsString(throwable)); defaultUncaughtExceptionHandler.uncaughtException(thread, throwable); } });
Note: Throwables is a class from guava
Option without Guava, but without a full stacktrace, only the original line number and method included in the report:
GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(this); applicationPreferences = new ApplicationPreferences(getApplicationContext()); tracker = googleAnalytics.newTracker(R.xml.tracker); tracker.enableExceptionReporting(true); String lastErrorString = applicationPreferences.getLastErrorString(); if (lastErrorString != null) { applicationPreferences.clearLastErrorString(); tracker.send(new HitBuilders.ExceptionBuilder().setDescription(lastErrorString).setFatal(true).build()); } final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable throwable) { applicationPreferences.setLastErrorString( new StandardExceptionParser(getApplicationContext(), null).getDescription(thread.getName(), throwable) ); defaultUncaughtExceptionHandler.uncaughtException(thread, throwable); } });