简体   繁体   English

Google Anaytlics v4 Android投放错误

[英]Google Anaytlics v4 Android casting error

I Cannot for some reason get the Anaytics simple screen view tracking to work, I have followed all the documentation, however am getting a casting issue: 由于某种原因,我无法使Anaytics简单屏幕视图跟踪正常工作,我已经阅读了所有文档,但是遇到了投放问题:

This is how I am trying to call the code within my onCreate(): 这就是我尝试在onCreate()中调用代码的方式:

Tracker t = ((Analytics) getApplication()).getTracker(Analytics.TrackerName.APP_TRACKER);
t.setScreenName("Home");
t.send(new HitBuilders.AppViewBuilder().build());

However whenever I try to run it I get a casting error, please see below for my Log error message: 但是,每当我尝试运行它时,都会出现转换错误,请参阅下面的Log错误消息:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.test/com.test.test.Menu}: java.lang.ClassCastException: android.app.Application cannot be cast to com.test.test.Analytics

Edit - Another attempt: 编辑 -另一尝试:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="ga_sessionTimeout">300</integer>
    <bool name="ga_autoActivityTracking">true</bool>
    <screenName name="com.test.test.Menu">
        Analytics Menu
    </screenName>
    <!--  The following value should be replaced with correct property id. -->
    <string name="ga_trackingId">UA-XXXXXXX-1</string> <!-- I have added my actual trackid in my code -->
</resources>

// Then I use this within my Menu.onCreate()
 ((Analytics) getApplication()).getTracker(Analytics.TrackerName.APP_TRACKER);

However I am still getting the same casting error stated above 但是我仍然收到上面所述的相同的铸造错误

It looks like your error has nothing to do with Analytics. 看来您的错误与Analytics(分析)无关。 Check if you have replaced the Application class in your manifest with com.test.test.Analytics. 检查清单中的Application类是否已用com.test.test.Analytics替换。 It seems you are still using the default Android application class. 看来您仍在使用默认的Android应用程序类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM