Firebase Database Query Not Working

不想你离开。 提交于 2019-12-11 16:57:20

问题


I am trying to create a Firebase Login and Register App. I have setup that At the time of registration android id will save to the database. If the Android Id exits with another account the user can't create account . when i run the app and try to register an account its shows "Registering Please Wait..." and nothings happens . How can i fix this?


回答1:


To solve this problem and all your problems regarding authentication is suggest you using Firebase Authentication.

It's very easy to implement and you'll don't have in the future any code to maintain.

To find serial number of Android device please use this code:

TelephonyManager tManager = (TelephonyManager)myActivity.getSystemService(Context.TELEPHONY_SERVICE);
String androidSerialNumber = tManager.getDeviceId();

Having this androidSerialNumber you can use it to save it in your database.

0down voteaccepted

Another approach will be to change The Rule Of Database like this:

{ "rules": 
     { ".read": "true",
       ".write": "auth != null"
     }
 }



回答2:


Change the code to this .

if(task.isSuccessful()){
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
rootRef.child(firebaseAuth.getCurrentUser().getUid()).child("Id").setValue(android_id);
progressDialog.dismiss();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
finish();
}

and also dismiss the progressDialog when the query is canceled

@Override
        public void onCancelled(DatabaseError databaseError) {
        progressDialog.dismiss();
        }
    });


来源:https://stackoverflow.com/questions/46725111/firebase-database-query-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!