Android的谷歌Analytics(分析)造成黑色屏幕 [英] Android Google Analytics Causing Black Screen

查看:125
本文介绍了Android的谷歌Analytics(分析)造成黑色屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是跟着<一href="https://benwilcock.word$p$pss.com/2014/04/11/working-with-google-analytics-api-v4-for-android/">this教程加入谷歌Analytics(分析)SDK V4成一个Android应用程序。现在的问题是,当我运行应用程序,它只是给任何观点我已经设置与跟踪黑屏。例如下面是从启动画面后的第一个视图中的onCreate,ONSTART和的onStop方法。启动画面加载罚款,然后我刚上车的看法黑屏。如果您注释掉分析code一切工作

  @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.landing_screen);


        //获取跟踪器(应自动报告)


        //定义字体使用
        字样字体= Typeface.createFromAsset(getAssets(),字体/ cabinregular.otf);

        //字体设置为所有元素
        ((TextView中)findViewById(R.id.textFlat))setTypeface(字体)。
        ((TextView中)findViewById(R.id.textCool))setTypeface(字体)。
        ((TextView中)findViewById(R.id.textWarm))setTypeface(字体)。
        ((TextView中)findViewById(R.id.textPastels))setTypeface(字体);
        ((TextView中)findViewById(R.id.textDecades))setTypeface(字体)。
        ((TextView中)findViewById(R.id.textNeutrals))setTypeface(字体)。
        ((TextView中)findViewById(R.id.textMidTones))setTypeface(字体);
        //((TextView中)findViewById(R.id.appHeaderText))setTypeface(字体)。


        //创建所有的听众捕捉按钮presses
        的ImageButton buttonFlat =(的ImageButton)findViewById(R.id.buttonFlat);
        buttonFlat.setOnClickListener(本);
        的ImageButton buttonCool =(的ImageButton)findViewById(R.id.buttonCool);
        buttonCool.setOnClickListener(本);
        的ImageButton buttonWarm =(的ImageButton)findViewById(R.id.buttonWarm);
        buttonWarm.setOnClickListener(本);
        的ImageButton buttonPastels =(的ImageButton)findViewById(R.id.buttonPastels);
        buttonPastels.setOnClickListener(本);
        的ImageButton buttonDecades =(的ImageButton)findViewById(R.id.buttonDecades);
        buttonDecades.setOnClickListener(本);
        的ImageButton buttonNeutrals =(的ImageButton)findViewById(R.id.buttonNeutrals);
        buttonNeutrals.setOnClickListener(本);
        的ImageButton buttonMidTones =(的ImageButton)findViewById(R.id.buttonMidTones);
        buttonMidTones.setOnClickListener(本);

        ((colorlibApplicationClass)getApplication())getTracker(colorlibApplicationClass.TrackerName.APP_TRACKER)。




    }

    公共无效的OnStart()
    {
        super.onStart();
        //获取Analytics(分析)跟踪报告应用程序启动和放大器;放大器;未捕获的异常等。
        GoogleAnalytics.getInstance(本).reportActivityStart(本);
    }

    公共无效的onStop()
    {
        super.onStop();
        //停止分析跟踪
        GoogleAnalytics.getInstance(本).reportActivityStop(本);
    }
 

下面是应用程序类;

 包com.exampleapp.colorlib;



        进口android.app.Application;

        进口com.google.android.gms.analytics.GoogleAnalytics;
        进口com.google.android.gms.analytics.Tracker;

        进口的java.util.HashMap;

公共类colorlibApplicationClass扩展应用{

    //下面一行应改为包括正确的属性ID。
    私有静态最后弦乐PROPERTY_ID =UA除去-FOR-SECURITY;

    //日志TAG
    私有静态最后字符串变量=MyApp的;

    公共静态INT GENERAL_TRACKER = 0;

    公共枚举TrackerName {
        APP_TRACKER,//跟踪器只用在这个应用程序。
        GLOBAL_TRACKER,//使用由一家公司所有的应用程序跟踪。例如:卷起跟踪。
        ECOMMERCE_TRACKER,//使用由一家公司所有的应用程序跟踪。例如:卷起跟踪。

    }

    HashMap的&LT; TrackerName,跟踪&GT; mTrackers =新的HashMap&LT; TrackerName,跟踪&GT;();

    公共colorlibApplicationClass(){
        超();
    }

    同步跟踪getTracker(TrackerName trackerId){
        如果(!mTrackers.containsKey(trackerId)){

            GoogleAnalytics分析= GoogleAnalytics.getInstance(本);
            跟踪T =(trackerId == TrackerName.APP_TRACKER)? analytics.newTracker(R.xml.app_tracker)
                    (trackerId == TrackerName.GLOBAL_TRACKER)? analytics.newTracker(PROPERTY_ID)
                    :analytics.newTracker(R.xml.ecommerce_tracker);
            mTrackers.put(trackerId,T);



        }
        返回mTrackers.get(trackerId);
    }
}
 

解决方案

这是最后的一个问题。这里检查获取更多信息。

同时,也许这是最好使用旧版本。这一次正常工作:

编译com.google.android.gms:玩-服务:6.1 +

编辑:删除全局配置从AndroidManifest元数据运行良好。

I just followed this tutorial for adding Google Analytics SDK v4 into an android app. Problem now is that when I run the app it just gives a black screen on any view I've setup with tracking. For example below the is the onCreate, onStart and onStop methods from the first view after the splash screen. The splash screen loads fine, then I just get a black screen on the view. If you commented out the analytics code everything work

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


        //Get a Tracker (should auto-report)


        //Define font for use
        Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/cabinregular.otf");

        //Set font to all elements
        ((TextView) findViewById(R.id.textFlat)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textCool)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textWarm)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textPastels)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textDecades)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textNeutrals)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textMidTones)).setTypeface(typeface);
        //((TextView) findViewById(R.id.appHeaderText)).setTypeface(typeface);


        //Create all the listeners to catch button presses
        ImageButton buttonFlat = (ImageButton) findViewById(R.id.buttonFlat);
        buttonFlat.setOnClickListener(this);
        ImageButton buttonCool = (ImageButton) findViewById(R.id.buttonCool);
        buttonCool.setOnClickListener(this);
        ImageButton buttonWarm = (ImageButton) findViewById(R.id.buttonWarm);
        buttonWarm.setOnClickListener(this);
        ImageButton buttonPastels = (ImageButton) findViewById(R.id.buttonPastels);
        buttonPastels.setOnClickListener(this);
        ImageButton buttonDecades = (ImageButton) findViewById(R.id.buttonDecades);
        buttonDecades.setOnClickListener(this);
        ImageButton buttonNeutrals = (ImageButton) findViewById(R.id.buttonNeutrals);
        buttonNeutrals.setOnClickListener(this);
        ImageButton buttonMidTones = (ImageButton) findViewById(R.id.buttonMidTones);
        buttonMidTones.setOnClickListener(this);

        ((colorlibApplicationClass) getApplication()).getTracker(colorlibApplicationClass.TrackerName.APP_TRACKER);




    }

    public void onStart()
    {
        super.onStart();
        //Get an Analytics tracker to report app starts &amp; uncaught exceptions etc.
        GoogleAnalytics.getInstance(this).reportActivityStart(this);
    }

    public void onStop()
    {
        super.onStop();
        //Stop the analytics tracking
        GoogleAnalytics.getInstance(this).reportActivityStop(this);
    }

Here's the application class;

package com.exampleapp.colorlib;



        import android.app.Application;

        import com.google.android.gms.analytics.GoogleAnalytics;
        import com.google.android.gms.analytics.Tracker;

        import java.util.HashMap;

public class colorlibApplicationClass extends Application {

    // The following line should be changed to include the correct property id.
    private static final String PROPERTY_ID = "UA-REMOVED-FOR-SECURITY";

    //Logging TAG
    private static final String TAG = "MyApp";

    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 the apps from a company. eg: roll-up tracking.

    }

    HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

    public colorlibApplicationClass() {
        super();
    }

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

            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(R.xml.app_tracker)
                    : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(PROPERTY_ID)
                    : analytics.newTracker(R.xml.ecommerce_tracker);
            mTrackers.put(trackerId, t);



        }
        return mTrackers.get(trackerId);
    }
}

解决方案

It's a problem of the last version. Check here for more info.

Meanwhile maybe it's better to use an older version. This one works fine:

compile 'com.google.android.gms:play-services:6.1.+'

Edit: Removing the global configuration meta-data from the AndroidManifest worked fine.

这篇关于Android的谷歌Analytics(分析)造成黑色屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆