注册用户时Firebase遇到问题

时间:2020-06-25 10:26:19

标签: java android-studio firebase-realtime-database firebase-authentication

我有一个应用程序,可将用户的店铺数据插入SQLite数据库。数据包括商店名称,商店位置和商店联系方式。我正在尝试在Firebase数据库上获取该数据。为此,借助于游标,正在检索数据并将其传递给FirebaseDatabase。但是这个任务失败了 以下是代码 使用该应用程序时不需要电子邮件,因此密码是在应用程序内生成电子邮件和密码的原因。

public void RegisterUser(View view)
    {
        Cursor shopData = demoSQLite.getData();

        if(shopData.getCount() == 0)
        {
            Toast.makeText(this, "No data Found", Toast.LENGTH_SHORT).show();
        }
        else
        {
            while(shopData.moveToNext())
            {
                shopNameData = shopData.getString(0);
                shopLocationData = shopData.getString(1);
                shopContactData = shopData.getString(2);
            }
        }

        String shopEmail = shopNameData + "_" + shopLocationData + "@gmail.com";
        String passwordData = "password@123";

        Log.i("User", shopEmail + passwordData);

        firebaseAuth.createUserWithEmailAndPassword(shopEmail, passwordData)
                .addOnCompleteListener(new OnCompleteListener<AuthResult>()
                {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task)
                    {
                        if(task.isSuccessful())
                        {
                            User user = new User(shopNameData, shopLocationData, shopContactData);

                            FirebaseDatabase.getInstance().getReference("Users")
                                    .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                    .setValue(user).addOnCompleteListener
                                    (new OnCompleteListener<Void>()
                                        {
                                            @Override
                                            public void onComplete(@NonNull Task<Void> task)
                                            {
                                                if (task.isSuccessful())
                                                {
                                                    Log.i("User Data", "Data is uploaded");
                                                }
                                                else
                                                {
                                                    Log.i("User Data", "Data is not uploaded");
                                                }
                                            }
                                        });
                        }

                    }
                })
                .addOnFailureListener(new OnFailureListener()
                {
                    @Override
                    public void onFailure(@NonNull Exception e)
                    {
                        Log.i("Task", "Failed"); // While task is failed this message is displayed.
                    }
                });

    }

错误是

I/Task: Failed 
V/FA: Inactivity, disconnecting from the service
I/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@d9d02e

1 个答案:

答案 0 :(得分:0)

清单文件中是否具有Internet权限?

如果没有,则将此行添加到您的AndroidManifest.xml-

<uses-permission android:name="android.permission.INTERNET" />

希望这会有所帮助:)