Google Analytics Android App Integration
<p>this is my first time integrating Google Analytics with an Android app and I'm having troubles following these indications
<a href="https://developers.google.com/analytics/devguides/collection/android/v4/" rel="nofollow">https://developers.google.com/analytics/devguides/collection/android/v4/</a></p>

<p>It looks like that when adding this part of the code to MainActivity.java it doesn't work so I'm not able to compile the app.</p>

<p>// Obtain the shared Tracker instance.</p>

<pre><code>AnalyticsApplication application = (AnalyticsApplication) getApplication();
mTracker = application.getDefaultTracker();
</code></pre>

<p>my code:</p>

<p>build.gradle (app)</p>

<pre><code>      apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"

        defaultConfig {
            applicationId "com.developername.myapp"

            manifestPlaceholders = [manifestApplicationId: "${applicationId}",
                                    onesignal_app_id: "XXX",
                                    onesignal_google_project_number: "XXX"]

            minSdkVersion 15
            targetSdkVersion 23
            versionCode 6
            versionName "2.6"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.2.0'
        compile 'com.google.android.gms:play-services-ads:9.0.2'
        compile 'com.android.support:gridlayout-v7:23.2.0'
        compile 'com.onesignal:OneSignal:2.+@aar'
        compile 'com.google.android.gms:play-services-gcm:9.0.2'
        compile 'com.google.android.gms:play-services-analytics:9.0.2'
    }
    apply plugin: 'com.google.gms.google-services'
</code></pre>

<p>build.gradle (project)</p>

<pre><code>    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
</code></pre>

<p>Application.java</p>

<pre><code>    package com.developername.myapp;

import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import android.util.Log;

import org.json.JSONObject;
import com.onesignal.OneSignal;


public class Radio extends Application{
    private Tracker mTracker;
    synchronized public Tracker getDefaultTracker() {
        if (mTracker == null) {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            mTracker = analytics.newTracker(R.xml.global_tracker);
        }
        return mTracker;
    }

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

        OneSignal.startInit(this)
                .setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
                .setAutoPromptLocation(true)
                .init();
    }



    private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
        /**
         * Callback to implement in your app to handle when a notification is opened from the Android status bar or
         * a new one comes in while the app is running.
         * This method is located in this Application class as an example, you may have any class you wish implement NotificationOpenedHandler and define this method.
         *
         * @param message        The message string the user seen/should see in the Android status bar.
         * @param additionalData The additionalData key value pair section you entered in on onesignal.com.
         * @param isActive       Was the app in the foreground when the notification was received.
         */
        @Override
        public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
            String additionalMessage = "";

            try {
                if (additionalData != null) {
                    if (additionalData.has("actionSelected"))
                        additionalMessage += "Pressed ButtonID: " + additionalData.getString("actionSelected");

                    additionalMessage = message + "\nFull additionalData:\n" + additionalData.toString();
                }

                Log.d("OneSignalExample", "message:\n" + message + "\nadditionalMessage:\n" + additionalMessage);
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }


    }
}
</code></pre>

<p>MainActivity.java</p>

<pre><code>package com.developername.myapp.activity;

import android.content.Intent;
import android.os.Bundle;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.developername.myapp.R;
import com.developername.myapp.Radio;
import com.developername.myapp.fragment.MainFragment;



public class MainActivity extends BaseActivity{
        AdView mAdView;
    private static boolean activityStarted;

    Radio application = (Radio) getApplication();
    mTracker = application.getDefaultTracker();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        if (activityStarted
                &amp;&amp; getIntent() != null
                &amp;&amp; (getIntent().getFlags() &amp; Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
            finish();
            return;
        }

        activityStarted = true;

        mAdView = (AdView) findViewById(R.id.ad_view);


        // Create an ad request. Check your logcat output for the hashed device ID to
        // get test ads on a physical device. e.g.
        // "Use AdRequest.Builder.addTestDevice("ABCDEF012345") to get test ads on this device."
        AdRequest adRequest = new AdRequest.Builder().build();


        // Start loading the ad in the background.
        mAdView.loadAd(adRequest);

        addFragment(new MainFragment(), true);

    }
}
</code></pre>

<p>Android Studio seems to be finding an error at</p>

<pre><code>Radio application = (Radio) getApplication();
mTracker = application.getDefaultTracker();
</code></pre>

<p>What I'm doing wrong?</p>

<p>Help please.</p>

<p>Thanks</p>