简体   繁体   English

Firebase 在 android 工作室中没有响应

[英]Firebase not responding in android studio

I am trying to insert user data into the real-time database(Firebase).我正在尝试将用户数据插入实时数据库(Firebase)。 But when I run the app on an emulator or on my phone it just keeps loading(I set up a loadingBar to dismiss when a response is received) I tried going through the logcat to find an error message I got this但是当我在模拟器或手机上运行该应用程序时,它只会继续加载(我设置了一个 loadingBar 以在收到响应时关闭)我尝试通过 logcat 找到一条错误消息我得到了这个

Fetching config failed.获取配置失败。 code, error: 0, java.net.UnknownHostException: Unable to resolve host "app-measurement.com": No address associated with hostname: com.google.android.gms.measurement.internal.zzeq.run(com.google.android.gms:play-services-measurement@@20.0.0:26)代码,错误:0,java.net.UnknownHostException:无法解析主机“app-measurement.com”:没有与主机名关联的地址:com.google.android.gms.measurement.internal.zzeq.run(com.google. android.gms:play-services-measurement@@20.0.0:26)

I checked the rules, the dependencies looked through the web I can't seem to find what I missed.我检查了规则,依赖项查看了 web 我似乎找不到我错过的内容。

I thought I should mention the first time I tried using firebase I faced the same problem on a less serious project so I didn't sort it out.我想我应该提到我第一次尝试使用 firebase 在一个不太严重的项目上遇到了同样的问题,所以我没有解决它。 That time I was using FIrebaseAuth so I decided to use a different approach this time.那时我使用的是 FIrebaseAuth,所以这次我决定使用不同的方法。 here is the signIn code.这是登录代码。

private void allowAccessAccount(String phoneNumber, String password) {
    final DatabaseReference rootRef;
    rootRef = FirebaseDatabase.getInstance().getReference();

    rootRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            if (dataSnapshot.child(PARENT_DB_NAME).child(phoneNumber).exists()) {

                User userData = dataSnapshot.child(PARENT_DB_NAME).child(phoneNumber)
                        .getValue(User.class);

                if (userData.getPhone().equals(phoneNumber)) {

                    if (userData.getPassword().equals(password)) {

                        if (PARENT_DB_NAME.equals("Admins")) {

                            Toast.makeText(SignInActivity.this, "Success", Toast.LENGTH_SHORT).show();
                            loadingBar.dismiss();

                            //Open Home Activity
                            startActivity(new Intent(SignInActivity.this, AdminPanel.class));
                            finish();


                        } else if (PARENT_DB_NAME.equals("Users")) {

                            Toast.makeText(SignInActivity.this, "Success", Toast.LENGTH_SHORT).show();
                            loadingBar.dismiss();

                            //Get User Data
                            Prevalent.currentOnlineUsr = userData;

                            //Open Home Activity
                            startActivity(new Intent(SignInActivity.this, HomeActivity.class));
                            finish();

                        }
                    } else {

                        loadingBar.dismiss();
                        inputPassword.setError("Incorrect password");

                    }
                }
            } else {

                inputPhoneNumber.setError("Not registered");
                loadingBar.dismiss();
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError error) {

            Toast.makeText(SignInActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show();

        }
    });
}

Here is the signUp code这是注册码

private void signUpUser(String username, String phoneNumber, String password) {
    final DatabaseReference rootRef;
    rootRef = FirebaseDatabase.getInstance().getReference();

    rootRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            if (!(dataSnapshot.child("Users").child(phoneNumber).exists())){

                HashMap<String, Object> userDataMap = new HashMap<>();

                userDataMap.put("username", username);
                userDataMap.put("phone", phoneNumber);
                userDataMap.put("password", password);

                rootRef.child("Users").child(phoneNumber).updateChildren(userDataMap)
                        .addOnCompleteListener(new OnCompleteListener<Void>() {
                            @Override
                            public void onComplete(@NonNull Task<Void> task) {
                                if (task.isSuccessful()){

                                    //Account creation successful
                                    Toast.makeText(SignUpActivity.this, "Success", Toast.LENGTH_SHORT).show();
                                    loadingBar.dismiss();

                                    //Open Sign In Activity
                                    startActivity(new Intent(SignUpActivity.this,SignInActivity.class));
                                }
                                else {
                                    //Account creation Failed
                                    loadingBar.dismiss();
                                    Toast.makeText(SignUpActivity.this, "Failed", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
            } else {
                inputPhoneNumber.setError("Already registered");
                loadingBar.dismiss();
            }
        }
        @Override
        public void onCancelled(@NonNull DatabaseError error) {

        }
    });

}

Do you have an (ad)blocker?你有(广告)拦截器吗? can you resolve app-measurement.com?你能解决 app-measurement.com 吗? What does nslookup app-measurement.com say? nslookup app-measurement.com说什么?

I don't know exactly what went wrong as I ran through every little thing over 5 times looking for where I went wrong.我不知道到底出了什么问题,因为我把每件小事都跑了 5 次以上,寻找哪里出了问题。 I fixed it by removing firebase and letting the assistant add it for me.我通过删除 firebase 并让助手为我添加它来修复它。 I also removed the Jcenter repository plus I changed the email I was using for android studio to correspond with the email I was using for the project.我还删除了 Jcenter 存储库,并更改了我用于 android 工作室的 email 以与我用于该项目的 email 相对应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM