My application uses Google Analytics to track exceptions and crashes (among other thigs). I use this function to get the stacktrace:
public static void sendErrorReportViaGoogleAnalytics(Exception e) {
e.printStackTrace();
Tracker myTracker = EasyTracker.getTracker();
myTracker.sendException(getDescription(e), false);
}
public static String getDescription(Exception t) {
final StringBuilder result = new StringBuilder();
result.append(t.toString());
result.append(',');
String oneElement;
for (StackTraceElement element : t.getStackTrace()) {
oneElement = element.toString();
result.append(oneElement);
result.append(",");
}
return result.toString();
}
This works fine, when talking about exceptions, I just call sendErrorReportViaGoogleAnalytics() in the catch part of my exception handling codes, but when it comes to crashes, I only get one line of the stacktrace, like
Binary XML file line #11: Error inflating class fragment
I set
<bool name="ga_reportUncaughtExceptions">true</bool>
in analytics.xml, as I'm using EasyTracker.
What should I do to get the full stacktrace in case of crashes as well?
Just faced with this problem. Simply paste the given code to BaseApplication.onCreate() method of your project or to other place to set the custom ExceptionReporter for uncaught exceptions. And don't forget to declare the given flag in analytics.xml.
Custom uncaught exceptions reporter:
Since you didn't describe what you actually did in order to catch the crashes then I can only send you to the docs: https://developers.google.com/analytics/devguides/collection/android/v2/exceptions
If you are using EasyTracker you can declare:
otherwise you can implement the ExceptionReporter class as described and attach it to your thread.