android – 将Google Analytics添加到我的应用中时出现XML错误

前端之家收集整理的这篇文章主要介绍了android – 将Google Analytics添加到我的应用中时出现XML错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在我的应用程序中附加谷歌分析谷歌分析.

我正在关注如何在谷歌GA主页中添加谷歌分析.
(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文件夹&重建项目对我有帮助.
原文链接:https://www.f2er.com/android/313711.html

猜你在找的Android相关文章