android - How can I show my contact phone numbers and get one of the phone numbers for use on my app? -


i have app has show phone contact list. user has select 1 phone number , have use phone number programmatically on app. how can it?

code examples great.

just wire button onbrowsefornumbersbuttonclicked() method... drop code in underneath formattedphonenumber line... , you're go.

import android.app.activity; import android.content.intent; import android.database.cursor; import android.net.uri; import android.provider.contactscontract.commondatakinds.phone; import android.util.log; import android.view.view;  public class testactivity extends activity {      private static final int request_contact_number = 123456789;      /** pops "select phone number" window */     public void onbrowsefornumbersbuttonclicked(view view) {         intent contactpickerintent = new intent(intent.action_pick, phone.content_uri);         startactivityforresult(contactpickerintent, request_contact_number);     }      protected void onactivityresult(int requestcode, int resultcode, intent data) {         if (resultcode == result_ok) {             if(data != null && requestcode == request_contact_number) {                   uri uriofphonenumberrecord = data.getdata();                 string idofphonerecord = uriofphonenumberrecord.getlastpathsegment();                 cursor cursor = getcontentresolver().query(phone.content_uri, new string[]{phone.number}, phone._id + "=?", new string[]{idofphonerecord}, null);                 if(cursor != null) {                         if(cursor.getcount() > 0) {                             cursor.movetofirst();                             string formattedphonenumber = cursor.getstring( cursor.getcolumnindex(phone.number) );                             log.d("testactivity", string.format("the selected phone number is: %s", formattedphonenumber));                         }                         cursor.close();                 }             }             else {                 log.w("testactivity", "warning: corrupted request response");             }         }         else if (resultcode == result_canceled) {             log.i("testactivity", "popup canceled user.");          }         else {             log.w("testactivity", "warning: unknown resultcode");         }     } } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -