PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 6, 2022

[FIXED] How to get different types of mobile numbers from contacts in android?

 November 06, 2022     android, contacts     No comments   

Issue

Using the following Code:

int index3 = phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); But it only gets one number and i also don't know which type of number it is. I want to get phone of type mobile , work , home etc. What would be the code for that ?


Solution

Figured it out you can simply use a switch statement on the TYPE and get different numbers and their type

CODE:

       while (phoneCursor.moveToNext()) {
                int index3 = phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
                int type = phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
                int type1 = phoneCursor.getInt(type);

                switch (type1) {
                    case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
                        numberWork = phoneCursor.getString(index3);
                        break;
                    case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
                        numberMobile = phoneCursor.getString(index3);
                        break;
                    case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
                        numberHome = phoneCursor.getString(index3);
                        break;

                }
            }


Answered By - peerzada burhan
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing