5

I have retrieved the value 1234 and now i require get its parentI am building a simple chat application in android with Firebase as backend.

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();




                        }
                    }

I have registration page set up such that the users' contact details get stored under UID(genrated by firebase). I have retrieved the common contacts using the code above. I require the user to send a push message to that common number. However I am not able to find a way to retrace the UID of which the number belongs to. I am retrieving common number so that I get a list of friends who are using my Application. So I am confused if I Should hard code this or write in API. Please give me an example if anyone has a solution

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ananymous59
  • 200
  • 1
  • 14
  • 1
    Hi Praveen. It sounds like your application will need to access the address book of the user's phone, which is something Firebase security rules cannot do (since they run on the Firebase server). Unfortunately your question is way too broad to answer in its current form. It'll be easier to help you if you share a minimal example of what you've tried, what you expect that code to do and what it is doing instead: http://stackoverflow.com/help/mcve – Frank van Puffelen Dec 11 '14 at 16:52
  • I am sorry for my broad question now I have restructured my question....please help me – ananymous59 Dec 16 '14 at 09:31
  • 2
    @PraveenMohan Did you implemented One to one chat using Firebase? Because i cant find related to one to one chat in Firebase api. – Umang Kothari Feb 17 '15 at 10:36
  • @PraveenMohan, can you please show data structure you used for one-to-one chat application? – Veer Mar 30 '15 at 05:05
  • @ananymous59 can u pls share one to one chat structure using firebase – Erum Jan 02 '17 at 07:03

0 Answers0