gpt4 book ai didi

java - 无法从静态上下文引用非静态字段 mFirebaseAnalytics

转载 作者:行者123 更新时间:2023-12-02 09:11:05 26 4
gpt4 key购买 nike

我正在使用 Buildbox。我在 Buildbox 中定义了一个自定义 openURL 方法。我正在尝试通过事件来追踪世界。如何在静态方法中访问非静态 mFirebaseAnalytics 实例?

package com.secrethq.utils;

import java.lang.ref.WeakReference;
import java.io.File;
import java.io.FileFilter;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Pattern;
import java.nio.IntBuffer;

import com.google.firebase.analytics.FirebaseAnalytics;

import android.app.Activity;


public class PTServicesBridge extends Activity
implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

private FirebaseAnalytics mFirebaseAnalytics;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
}


public static void openUrl( String url ){
Log.v(TAG, "PTServicesBridge -- Open URL " + url);

PTServicesBridge.urlString = url;

Bundle params = new Bundle();
params.putString("levelname", url);
mFirebaseAnalytics.logEvent("levels", params); //Problematic line it gives error.



}


}

有问题的线路:

 mFirebaseAnalytics.logEvent("levels", params); //Problematic line it gives error.

最佳答案

我刚刚挖掘了 buildbox 代码,这是您完成任务的方法!

使用 PTServicesBridge.s_activity 在方法内获取 FirebaseAnalytics 实例。

public static void openUrl( String url ){
Log.v(TAG, "PTServicesBridge -- Open URL " + url);

PTServicesBridge.urlString = url;

Bundle params = new Bundle();
params.putString("levelname", url);

// Get FirebaseAnalytics Object
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(PTServicesBridge.activity);
mFirebaseAnalytics.logEvent("levels", params); //Problematic line it gives error.
}

关于java - 无法从静态上下文引用非静态字段 mFirebaseAnalytics,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59415147/

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