Comparing EditText String With Firebase Database's Child Value
Solution 1:
Alright mate. The reason why your ValueEventListener
's onDataChange
isn't getting called is that you're not authorized to edit or read your database. This happens because the default security settings for a firebase real-time database disallows any read or write without an authenticated user. To prove this observe your warning
logs inside Android Monitor. (The blue ones.) It will show a caught exception mentioning permission denied from Firebase as soon as you click submit.
Read about Firebase security from here.
For a quick solution what you can do is, you can allow read or writes without any sort of authentication. To do that edit your Realtime database rules
and add this instead of what's written there.
{
"rules": {
".read": true,
".write": true
}
}
I'm also gonna attach a screenshot for reference. You'll find this screen inside the firebase console. Inside the console click on your project and then on Database
to the left as shown.
This is a security lapse none the less, so to set up proper Authentication from your app, follow these steps. https://firebase.google.com/docs/auth/android/start/
Also, add a toString() to dataSnapshot.child("passcode").getValue()
like this to convert it to String as it's probably long.
String passc = dataSnapshot.child("passcode").getValue().toString();
Also, just to be sure. Add this line if you haven't already
FirebaseApp.initializeApp(this);
above your
mpasscode=FirebaseDatabase.getInstance().getReference().child("Councilpasscodes");
Hope it helps!
Solution 2:
Have you tried using .compareTo() method? if (passcode1.compareTo(passc) == 0) { }
Solution 3:
I think firebase is returning integer instead. You can put the quote to 1234 and try again or compare as integer.
Solution 4:
if you are using only numerics then equalsIgnoreCase
would do good or if there is no limit of type of character you use in counsilcode
then .match
would be good
Post a Comment for "Comparing EditText String With Firebase Database's Child Value"