android - Firebase - Check if data exist and add them -
i want check if user member of specific team, if user isn't ask join, if is, directed page. did find of similar question somehow still couldn't add user database. below code , code crash whenever click on 1 of list.
databasemembers = firebasedatabase.getinstance().getreference("members"); listviewteams.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> adapterview, view view, int i, long l) { //getting selected team team team = teams.get(i); checkmember(); //creating intent intent intent = new intent(getapplicationcontext(), chatroomactivity.class); //putting team name , id intent intent.putextra(team_id, team.getteamid()); intent.putextra(team_name, team.getteamname()); //starting activity intent startactivity(intent); } }); private void checkmember(){ firebaseuser user = firebaseauth.getcurrentuser(); final string teammember = user.getemail(); databasemembers.addlistenerforsinglevalueevent(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { if(datasnapshot.haschild(teammember)){ finish(); } else{ databasemembers.push().setvalue(teammember); } } @override public void oncancelled(databaseerror databaseerror) { } }); }
logcat:
04-07 12:44:41.167 19091-19091/com.example.user.stfv2 e/androidruntime: fatal exception: main process: com.example.user.stfv2, pid: 19091 com.google.firebase.database.databaseexception: invalid firebase database path: haha@gmail.com. firebase database paths must not contain '.', '#', '$', '[', or ']' @ com.google.android.gms.internal.zzbtf.zzjl(unknown source) @ com.google.firebase.database.datasnapshot.haschild(unknown source) @ com.example.user.stfv2.mainactivity$8.ondatachange(mainactivity.java:352) @ com.google.firebase.database.query$1.ondatachange(unknown source) @ com.google.android.gms.internal.zzbpx.zza(unknown source) @ com.google.android.gms.internal.zzbqx.zzzs(unknown source) @ com.google.android.gms.internal.zzbra$1.run(unknown source) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)
my database:
when user click on "heng" team, check if user's email exist in database, if isn't add user's email teammember. can add user created team, can't seem add users wants join later. appreciate if me. let me know if there's lack of information.
the problem firebase not accept .
(dot) symbol in key. in order use email address, need have encoding method. email addres must name@mail,com
(see ,
comma) in stead of nume@email.com in case. these methods encode , decode email address.
static string encodeuseremail(string useremail) { return useremail.replace(".", ","); } static string decodeuseremail(string useremail) { return useremail.replace(",", "."); }
this methods solve problem.
Comments
Post a Comment