如何将我的联系人与在Firebase数据库中上传的联系人进行比较 [英] how to compare my contact with the contacts uploaded in firebase database

查看:64
本文介绍了如何将我的联系人与在Firebase数据库中上传的联系人进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想向您展示我的Firebase数据库树

Firstly I would like to show you my Firebase database tree

-Users
   |
   ----959670000
   |      |
   |      ------name
   |
   + ----750890000
   +------859200000

我有一个以child作为用户的根节点.每当新用户注册时,它都会获得一个新的唯一ID ...,唯一ID是电话号码.现在,在我的Android应用程序"中,我检索了我的所有联系人,即手机号码中存在的电话号码.我只想将联系人中的每个电话号码与Firebase数据库中存在的电话号码进行比较,以便我将知道联系人中的哪个用户已注册.

I had a root node with child as a user. whenever new user registers it got new Unique Id... and the unique Id is the phone number. Now In My Android Application I retrieve all my contacts i.e. phone number present in my mobile number. All I want is to compare Each phone number in my contact to the phone number present in the firebase database so that I would get to know which user in my contact had got registered.

我要问的是实现问题中粗体部分的方法,请帮助我....由于过去4天的努力,我感到非常沮丧. 无论如何,thanx都是进阶......:-)

All I am trying to ask are the ways to achieve the bold part in my question please Help me....I am very upset since the past 4 days and trying to achieve. Anyways thanx in Advance....:-)

推荐答案

public boolean getAllUserList(final ArrayList<ContactPojo> contactList){//all contact list as an argument
        databaseReference();
        for (int i = 0; i < contactList.size(); i++) {
            checkingMatchedData(contactList.get(i).getPhone(),contactList.get(i));
        }
        return false;
    }

public void checkingMatchedData(String phone, final ContactPojo contPojo){
    Query query=reference.orderByChild("phone").equalTo(Long.parseLong(phone));
    ValueEventListener listener=new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if (dataSnapshot.getValue()!=null) {
                for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    UserPojo pojo = snapshot.getValue(UserPojo.class);
                    ContactPojo contactPojo = new ContactPojo();
                    contactPojo.setName(pojo.getName());
                    contactPojo.setPhone(String.valueOf(pojo.getPhone()));
                    contactPojo.setPhoto_uri(pojo.getImageUrl());
                    contactPojo.setUserId(pojo.getUserId());
                    contactPojo.setTypeOfData(101);//this is used to define type of user i.e 101 for registered user or 100 for unregistered
                    finalUserList.add(contactPojo);
                }
            }else {
                contPojo.setTypeOfData(100);
                finalUserList.add(contPojo);
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    };
    query.addListenerForSingleValueEvent(listener);
}
public void databaseReference(){
    reference= FirebaseDatabase.getInstance().getReference().child("Users");
}

这篇关于如何将我的联系人与在Firebase数据库中上传的联系人进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆