Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未在Flurry上跟踪Android设置性别参数 问题:_Android_Flurry - Fatal编程技术网

未在Flurry上跟踪Android设置性别参数 问题:

未在Flurry上跟踪Android设置性别参数 问题:,android,flurry,Android,Flurry,方法setAge和setUserId工作正确地记录在会话信息的Flurry事件日志部分,而不是SETSEXT方法 配置 格拉德尔-项目: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jce

方法setAge和setUserId工作正确地记录在会话信息的Flurry事件日志部分,而不是SETSEXT方法

  • 配置
  • 格拉德尔-项目:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
                buildscript {
                    repositories {
                        jcenter()
                    }
                    dependencies {
                        classpath 'com.android.tools.build:gradle:3.0.1'
                        classpath 'com.google.gms:google-services:3.1.0'
                        classpath 'com.android.tools.build:gradle:3.0.1'
    
    
                        // NOTE: Do not place your application dependencies here; they belong
                        // in the individual module build.gradle files
                    }
                }
    
                allprojects {
                    repositories {
                        jcenter()
    
                        maven {
                            url "https://maven.google.com"
                        }
                        google()
                    }
                }
    
                task clean(type: Delete) {
                    delete rootProject.buildDir
                }
    
    Gradle-模块应用程序

    apply plugin: 'com.android.application'
    
                android {
                    compileSdkVersion 25
    
                    defaultConfig {
                        applicationId "com.xunxujianjin.flashchatnewfirebase"
                        minSdkVersion 16
                        targetSdkVersion 25
                        versionCode 1
                        versionName "1.0"
                    }
                    buildTypes {
                        release {
                            minifyEnabled false
                            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                        }
                    }
                }
    
                dependencies {
                    compile fileTree(dir: 'libs', include: ['*.jar'])
                    testCompile 'junit:junit:4.12'
                    compile 'com.android.support:appcompat-v7:25.4.0'
                    compile 'com.android.support:design:25.4.0'
                    compile 'com.google.firebase:firebase-database:11.8.0'
                    compile 'com.google.firebase:firebase-auth:11.8.0'
                    compile 'com.flurry.android:ads:8.2.0'
                    compile 'com.flurry.android:analytics:8.2.0'
                }
    
                apply plugin: 'com.google.gms.google-services'
    
  • 后勤活动(着陆活动):

    包com.xunxujianjin.flashchatnewfirebase

            import android.content.Intent;
            import android.content.SharedPreferences;
            import android.os.Bundle;
            import android.support.annotation.NonNull;
            import android.support.v7.app.AlertDialog;
            import android.support.v7.app.AppCompatActivity;
            import android.text.TextUtils;
            import android.util.Log;
            import android.view.KeyEvent;
            import android.view.View;
            import android.view.inputmethod.EditorInfo;
            import android.widget.AutoCompleteTextView;
            import android.widget.EditText;
            import android.widget.TextView;
            import android.widget.Toast;
    
            import com.flurry.android.Constants;
            import com.flurry.android.FlurryAgent;
            import com.flurry.android.ads.FlurryGender;
            import com.google.android.gms.tasks.OnCompleteListener;
            import com.google.android.gms.tasks.Task;
            import com.google.firebase.auth.AuthResult;
            import com.google.firebase.auth.FirebaseAuth;
    
            import java.util.Random;
    
    
            public class LoginActivity extends AppCompatActivity {
    
                // constants
                final String FLURRY_API_KEY = "xxx";
                public static final String PREFS_NAME = "UserProfile";
                public static final Byte MALE = 1;
            //    public static final String USER_ID = "user id number";
    
                // TODO: Add member variables here:
                private FirebaseAuth mAuth;
                // UI references.
                private AutoCompleteTextView mEmailView;
                private EditText mPasswordView;
    
                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_login);
    
                    FlurryAgent.setAge(65);
                    FlurryAgent.setGender(Constants.FEMALE);
                    FlurryAgent.setGender(MALE);
                    FlurryAgent.setGender((byte) FlurryGender.MALE.getCode());
    
            // the different attempts to log gender:
    
                    Log.d("JBDEBUG", "setgender input is byte MALE: "+MALE);
                    Log.d("JBDEBUG", "setgender Constants.FEMALE is: "+Constants.FEMALE);
                    Log.d("JBDEBUG", "setgender Flurry Gender with getcode: "+(byte)FlurryGender.MALE.getCode());
    
                    new FlurryAgent.Builder()
                            .withLogEnabled(true)
                            .withCaptureUncaughtExceptions(true)
                            .withLogLevel(Log.VERBOSE)
                            .build(this, FLURRY_API_KEY);
    
    
                    checkForExistingUserID();
                    Log.d("display user id: ", " user id: "+read_userID());
    
                    mEmailView = (AutoCompleteTextView) findViewById(R.id.login_email);
                    mPasswordView = (EditText) findViewById(R.id.login_password);
    
                    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                        @Override
                        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
                            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                                attemptLogin();
                                return true;
                            }
                            return false;
                        }
                    });
    
                    // TODO: Grab an instance of FirebaseAuth
                    mAuth = FirebaseAuth.getInstance();
                }
    
                // Executed when Sign in button pressed
                public void signInExistingUser(View v) {
                    // TODO: Call attemptLogin() here
                    attemptLogin();
                }
    
                // Executed when Register button pressed
                public void registerNewUser(View v) {
                    Intent intent = new Intent(this, com.xunxujianjin.flashchatnewfirebase.RegisterActivity.class);
                    finish();
                    startActivity(intent);
                }
    
                // TODO: Complete the attemptLogin() method
                private void attemptLogin() {
                    String email = mEmailView.getText().toString();
                    String password = mPasswordView.getText().toString();
    
                    if (email.equals("") || password.equals("")) return;
                    Toast.makeText(this, "Login in progress", Toast.LENGTH_SHORT).show();
    
                    mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            Log.d("FlashChat", "Sign in with Email() on Complete " + task.isSuccessful());
    
                            if (!task.isSuccessful()) {
                                Log.d("FlashChat", "Problem signing in " + task.getException());
                                showErrorDialog("someming mas mwong");
                            } else {
                                Intent intent = new Intent(LoginActivity.this, MainChatActivity.class);
                                FlurryAgent.logEvent("user_log_in");
                                Log.d("flurry", "pos 5 login successful");
                                finish();
                                startActivity(intent);
                            }
                        }
                    });
                }
    
                String read_userID() {
                    SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
                    String uID = prefs.getString("user_id",null);
                    return uID;
                }
    
                String generateNumber() {
    
                    SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
    
                    // generate random number for user id
                    Random randomNumberGenerator = new Random();
                    int randomNumber = randomNumberGenerator.nextInt(1000);
                    String stringedNum = Integer.toString(randomNumber);
    
                    Long tsLong = System.currentTimeMillis();
                    String ts = tsLong.toString()+stringedNum;
                    Log.d("generateID", "generated num is: "+ts);
    
                    // write this random number as a value associated with user id key in client shared preferences
                    prefs.edit().putString("user_id", ts).apply();
                    Log.d("generateID Shared pref", "generated num in shared pref is: "+prefs.getString("user_id",null));
    
                    return ts;
                }
    
                public void checkForExistingUserID(){
    
    
                    String retrievedUserID = read_userID();
                    SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
    
                    // Check for an existing user id if not created, create it into shared pref and report it to flurry
                    if (TextUtils.isEmpty(retrievedUserID)) {
                    FlurryAgent.setUserId(generateNumber());
                    Log.d("login test", "user with no user id and whose got one: "+prefs.getString("user_id",null));
    
                } else {
                    FlurryAgent.setUserId(retrievedUserID);
                    Log.d("login test", "existing user_id in base declared to flurry: "+retrievedUserID);
                }
    
                }
    
                // TODO: Use FirebaseAuth to sign in with email & password
                // TODO: Show error on screen with an alert dialog
                private void showErrorDialog(String message) {
                    new AlertDialog.Builder(this)
                            .setTitle("Oh oh")
                            .setMessage(message)
                            .setPositiveButton(android.R.string.ok, null)
                            .setIcon(android.R.drawable.ic_dialog_alert)
                            .show();
                }
            }
    
            import android.content.Intent;
            import android.content.SharedPreferences;
            import android.os.Bundle;
            import android.support.v7.app.AppCompatActivity;
            import android.util.Log;
            import android.view.KeyEvent;
            import android.view.View;
            import android.widget.EditText;
            import android.widget.ImageButton;
            import android.widget.ListView;
            import android.widget.TextView;
    
            // import android.content.Intent;
            // import android.view.KeyEvent;
            // import android.widget.Button;
    
    
            import com.flurry.android.Constants;
            import com.flurry.android.FlurryAgent;
            import com.flurry.android.FlurryAgentListener;
            import com.flurry.android.ads.FlurryGender;
            import com.google.firebase.database.DatabaseReference;
            import com.google.firebase.database.FirebaseDatabase;
    
            public class MainChatActivity extends AppCompatActivity {
    
                // TODO: Add member variables here:
                private String mDisplayName;
                private ListView mChatListView;
                private EditText mInputText;
                private ImageButton mSendButton;
                private DatabaseReference mDatabaseReference;
                private ChatListAdapter mAdapter;
                public static final String PREFS_NAME = "UserProfile";
                private static final Byte MALE = 1;
                private static final Byte FEMALE = 0;
    
    
    
                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_main_chat);
    
                    // TODO: Set up the display name and get the Firebase reference
                    setupDisplayName();
                    mDatabaseReference = FirebaseDatabase.getInstance().getReference();
    
                    // Link the Views in the layout to the Java code
                    mInputText = (EditText) findViewById(R.id.messageInput);
                    mSendButton = (ImageButton) findViewById(R.id.sendButton);
                    mChatListView = (ListView) findViewById(R.id.chat_list_view);
    
                    // TODO: Send the message when the "enter" button is pressed
                    mInputText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                        @Override
                        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                            String name = mInputText.getText().toString();
                            sendMessage();
                            return true;
                        }
                    });
    
                    // TODO: Add an OnClickListener to the sendButton to send a message
                    mSendButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            sendMessage();
                        }
                    });
    
                    // TODO: Retrieve the display name from the Shared Preferences
                }
    
                    private void sendMessage(){
                        Log.d("FlashChat", "I sent something top merci ");
                        String input = mInputText.getText().toString();
                        if (!input.equals("")){
                            InstantMessage chat = new InstantMessage(input, mDisplayName);
                            mDatabaseReference.child("messages").push().setValue(chat);
                            mInputText.setText("");
                            FlurryAgent.logEvent("message sent");
                            Log.d("flurry", "pos 3 withing function 
    
  • //再次尝试记录她的性别,但在同一活动中没有成功:

    message sent event activated + set gender");
                                FlurryAgent.setGender(Constants.FEMALE);
                                FlurryAgent.setGender(FEMALE);
                                FlurryAgent.setGender((byte) FlurryGender.MALE.getCode());
                        }
                    }
    
                        private void setupDisplayName(){
                            SharedPreferences prefs = getSharedPreferences(RegisterActivity.CHAT_PREFS, MODE_PRIVATE);
                            mDisplayName = prefs.getString(RegisterActivity.DISPLAY_NAME_KEY, null);
                            if (mDisplayName == null) mDisplayName = "Anonymous";
                        }
    
                    // TODO: Grab the text the user typed in and push the message to Firebase
    
    
                    // TODO: Override the onStart() lifecycle method. Setup the adapter here.
                    @Override
                    public void onStart(){
                            super.onStart();
                            mAdapter = new ChatListAdapter(this, mDatabaseReference, mDisplayName);
                            mChatListView.setAdapter(mAdapter);
                        FlurryAgent.onStartSession(getApplicationContext());
                        Log.d("JBDEBUG", "onStartSession on mainchat activity");
                    }
    
                    @Override
                    public void onStop() {
                        super.onStop();
    
                        // TODO: Remove the Firebase event listener on the adapter.
                    mAdapter.cleanup();
    
    
                        FlurryAgent.onEndSession(getApplicationContext());
                        Log.d("jbstop", "onEndSession");
                        SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
                        prefs.edit().putString("user_id", "").apply();
                        Log.d("jbstop","user id: "+prefs.getString("erased user_id",null));
                        Log.d("jbstop","supposed to be stopped state in mainchat activity");
                    }
                }
    

    我想进一步深入调试,了解Flurry或client哪一方存在问题。提前感谢您的指导,

    您需要如下设置性别:-

    FlurryAgent.setGender(FlurryGender.FEMALE);
    

    如果我使用这个:FlurryAgent.setGender(FlurryGender.FEMALE),我会得到一个:“setGender字节不能应用于com.flurry.android.ads.FlurryGender”,尽管我导入了这个类:import com.flurry.android.ads.FlurryGender;导入com.flurry.android.fluryagent;我想我可能遗漏了什么,而且,在尝试编译时,我得到了这样一个错误:“不兼容的类型:FlurryGender不能转换为字节”