Firebase一对一聊天

时间:2014-12-11 06:45:31

标签: android firebase firebase-realtime-database rest-firebase

I have retrieved the value 1234 and now i require get its parent我正在使用Firebase作为后端在Android中构建一个简单的聊天应用程序。

ref3.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
                Map<String, Object> users = (Map<String, Object>) snapshot.getValue();
                System.out.println(users.values().toString());
                Set s = users.entrySet();
                Iterator itr = s.iterator();
                while (itr.hasNext()) {
                    Map.Entry m = (Map.Entry) itr.next();
                    m.getKey();
                    String myval = m.getValue().toString();
                    String spmyval[] = myval.split(", ");

                    System.out.println(spmyval[0] + " <-sp0 sp1-> " + spmyval[1]);
                    list=new ArrayList();

                    a1 = spmyval[0].split("=");

                    Cursor cur = getContentResolver().query(
                            ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
                    if (cur.getCount() > 0) {
                        while (cur.moveToNext()) {

                            // read id
                            String id = cur.getString(cur
                                    .getColumnIndex(ContactsContract.Contacts._ID));
                            /** read names **/
                            displayName = cur
                                    .getString(cur
                                            .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

                            System.out.println("DISPLAYNAMESssss:!!!!!!!!!!!!!!"+displayName+"::::::::");


                            /** Phone Numbers **/
                            Cursor pCur = getContentResolver().query(
                                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                    null,
                                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                            + " = ?", new String[]{id}, null);


                            String typeStr = null;
                            int i=0;
                            while (pCur.moveToNext()) {

                                num = pCur
                                        .getString(pCur
                                                .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                                number1=new String[]{num};

                                Log.e("Number by pavan",i +" " + number1[i]);
                                typeStr = pCur
                                        .getString(pCur
                                                .getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));

                                if(a1[1].equals(number1[i].replaceAll("[^\\d.]", ""))) {
                                    Log.e("COMMON:", a1[1]);




                                    i++;
                                }
                            }

                            pCur.close();




                        }
                    }

我设置了注册页面,以便用户的联系人详细信息存储在UID下(由firebase生成)。 我使用上面的代码检索了常见的联系人。我要求用户向该公共号码发送推送消息。但是我无法找到一种方法来回溯该数字所属的UID。我正在检索公共号码,以便获得正在使用我的应用程序的朋友列表。所以我很困惑,如果我应该硬编码或写入API。如果有人有解决方案,请举个例子

0 个答案:

没有答案