gpt4 book ai didi

java - 尝试实现 Google Analytics,错误跟踪器类无法解析为变量

转载 作者:行者123 更新时间:2023-12-01 11:41:03 26 4
gpt4 key购买 nike

我按照谷歌给出的说明并使用示例应用程序。 eclipse 在主屏幕中说,MyApplication 无法解析为变量,但是如果我按住 ctrl+单击它,它会跳转到 MyApplication.java...出了什么问题?

这是 MyApplication.java

public class MyApplication extends Application{

HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
private static final String PROPERTY_ID = "UA-61709726-1";



public static int GENERAL_TRACKER = 0;

public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
}

public MyApplication() {
super();
}

synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {

GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
: (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(
R.xml.global_tracker)
: analytics.newTracker(R.xml.ecommerce_tracker);
t.enableAdvertisingIdCollection(true);

mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);



}
}

这是 MainScreen.java

//...............
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


Tracker t = ( (MyApplication) .getApplication()).getTracker(
TrackerName.APP_TRACKER);

// Set screen name.
t.setScreenName("MainScreen");

// Send a screen view.
t.send(new HitBuilders.ScreenViewBuilder().build());

//................

我的 list :

 //................

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name=".MyApplication"> <!-- replace with your app class-->
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme" >

<meta-data
android:name="com.facebook.sdk.ApplicationId"

//................

最佳答案

您需要让 Android 知道您希望它使用自定义应用程序实现而不是默认的 android.app.Application 。为此,您需要添加 android:name="<your-app-class>"属性到您的 AndroidManifest.xml:

<manifest>
...
<application
android:name=".MyApplication"> <!-- replace with your app class-->
...
</application>
</manifest>

关于java - 尝试实现 Google Analytics,错误跟踪器类无法解析为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29526389/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com