gpt4 book ai didi

android - 将 Google Analytics 添加到我的应用程序时出现 XML 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:32:33 25 4
gpt4 key购买 nike

我想在我的应用中附加谷歌分析 google analytics。

我正在学习如何在 Google GA 主页中添加 Google Analytics。( https://developers.google.com/analytics/devguides/collection/android/v4/#manifest )

但是我在 ApplicationTracker.java 中有一个错误

在R.xml.global_tracker和R.xml.ecommerce_tracker中,xml有一条红线(有错误)

错误内容为“xml无法解析或不是字段”

我已经在处理谷歌搜索和 stackoverfliw 搜索以及如此多的搜索了。

很多人说这是关于android.R的

但我不会添加 android。我使用 com.myPackageName.R 很好。

有人可以解释一下吗?

后面是我的代码

ApplicationTracker.java

package com.zla.android;

import java.util.HashMap;
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import com.zla.android.R;

public class ApplicationTrackers extends Application{

private static final String PROPERTY_ID = "UA-XXXXXXXX-2";

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.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
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);
mTrackers.put(trackerId, t);

}
return mTrackers.get(trackerId);
}
}

global_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">

<integer name="ga_sessionTimeout">300</integer>

<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>

<!-- The screen names that will appear in reports -->
<string name="com.zla.android.MainActivity">MainActivity</string>

<string name="ga_trackingId">UA-XXXXXXXX-2</string>
</resources>

ecommerce_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="ga_sessionTimeout">300</integer>
<string name="ga_trackingId">UA-XXXXXXXX-2</string>
</resources>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zla.android"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />

<!-- about google analytics -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:largeHeap="true" >

<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.zla.android.SearchBrandActivity"
android:label="search page" />

<activity
android:name="com.zla.android.SearchFrameActivity"
android:label="search page" />

<activity
android:name="com.zla.android.ListActivity"
android:label="list page"
android:parentActivityName="com.zla.android.MainActivity" >
</activity>

<activity
android:name="com.zla.android.ListActivity_WishList"
android:label="list page"
android:parentActivityName="com.zla.android.MainActivity" >
</activity>

<activity
android:name="com.zla.android.DetailActivity"
android:label="detail page"
android:parentActivityName="com.zla.android.ListActivity" />

<!-- about google analytics -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity
android:name="com.zla.android.ApplicationTrackers"
android:label="google analytics"
android:parentActivityName="com.zla.android.MainActivity" />

</application>

</manifest>

最佳答案

我有同样的错误,当我创建 res/xml 文件夹并重建项目时,它对我有帮助。

关于android - 将 Google Analytics 添加到我的应用程序时出现 XML 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29449081/

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