Working around this bug: https://code.google.com/p/android/issues/detail?id=82157
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 21 Dec 2014 15:38:22 +0000 (16:38 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 21 Dec 2014 15:38:22 +0000 (16:38 +0100)
app/src/main/AndroidManifest.xml
app/src/main/java/name/gumartinm/weather/information/app/WeatherInformationApp.java

index 4c156e8..944f440 100644 (file)
         <meta-data
             android:name="com.google.android.gms.version"
             android:value="@integer/google_play_services_version" />
+        <!--
+            Commenting out because of this bug: https://code.google.com/p/android/issues/detail?id=82157
+            The programatic way seems to work.
         <meta-data
             android:name="com.google.android.gms.analytics.globalConfigResource"
             android:resource="@xml/global_tracker" />
+        -->
 
     </application>
 
index cca8dcf..b5e438d 100644 (file)
@@ -38,8 +38,13 @@ public class WeatherInformationApp extends Application {
         if (BuildConfig.DEBUG_MODE) {
             Timber.plant(new Timber.DebugTree());
         } else {
-            Timber.plant(new GoogleAnalyticsReportingTree(
-                    new GoogleAnalyticsTrackers(this.getApplicationContext())));
+            // Trying to avoid this bug: https://code.google.com/p/android/issues/detail?id=82157
+            // When Google fixes the bug I will be able to rely on the AndroidManifest.xml configuration.
+            final GoogleAnalyticsTrackers analyticsTrackers =
+                    new GoogleAnalyticsTrackers(this.getApplicationContext());
+            analyticsTrackers.setGlobalTracker();
+
+            Timber.plant(new GoogleAnalyticsReportingTree(analyticsTrackers));
         }
     }
 
@@ -47,6 +52,7 @@ public class WeatherInformationApp extends Application {
 
         private enum TrackerName {
             EXCEPTIONS_TRACKER, // Tracker used when logging caught exceptions in this app.
+            GLOBAL_TRACKER,     // Tracker used when logging uncaught exception in this app.
         };
 
         private final HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
@@ -57,6 +63,14 @@ public class WeatherInformationApp extends Application {
         }
 
         /**
+         * Trying to avoid this bug: https://code.google.com/p/android/issues/detail?id=82157
+         * When Google fixes the bug I will be able to rely on the AndroidManifest.xml configuration.
+         */
+        private void setGlobalTracker() {
+            this.getTracker(TrackerName.GLOBAL_TRACKER);
+        }
+
+        /**
          * Get tracker
          * @param trackerId
          * @return Tracker
@@ -68,6 +82,8 @@ public class WeatherInformationApp extends Application {
 
                 final Tracker t = (trackerId == TrackerName.EXCEPTIONS_TRACKER) ?
                         analytics.newTracker(R.xml.exceptions_tracker) :
+                        (trackerId == TrackerName.GLOBAL_TRACKER) ?
+                        analytics.newTracker(R.xml.global_tracker) :
                         analytics.newTracker(R.xml.exceptions_tracker);
 
                 // Do not retrieve user's information. I strongly care about user's privacy.