问题
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