get android contact phone number list

前端 未结 4 1849
逝去的感伤
逝去的感伤 2020-12-05 15:28

I am new to android.When i try to get contact names its working fine but i want to get numbers only, but i am not able to do so. My code is:-

package com.ex         


        
4条回答
  •  攒了一身酷
    2020-12-05 16:03

    Find the solution below, It will work for getting contact no from contactlist.

    You need permission like:

     android:name="android.permission.READ_CONTACTS"/>
    

    Then, Calling the Contact Picker:

     Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    

    Then,

     @Override
     public void onActivityResult(int reqCode, int resultCode, Intent data) {
     super.onActivityResult(reqCode, resultCode, data);
    
     switch (reqCode) {
      case (PICK_CONTACT) :
       if (resultCode == Activity.RESULT_OK) {
        Uri contactData = data.getData();
        Cursor c =  managedQuery(contactData, null, null, null, null);
         if (c.moveToFirst()) {
          String name = c.getString(c.getColumnIndexOrThrow(People.NAME));
          // TODO Whatever you want to do with the selected contact name.
        }
      }
      break;
      }
     }
    

提交回复
热议问题