This quickie will get you up and running if you need to display the android built in contact picker to select a phone number with a minimum amount of code.
Well, after looking for a quick way to select a phone number from within the built in Contact Picker in Android, I stumbled upon a remarkable number of articles with faulty information.
This is what finally worked!
private void selectContact() { // This intent will fire up the contact picker dialog Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI); startActivityForResult(intent, REQUEST_CONTACTPICKER); }
If all you wanted to do was to show the contact picker, this would be enough! However I suspect you wish to be notified of which phone number was selected.
To actually be notified of the selected result, we need to override the onActivityResult method. This assumes you're implementing the functionality inside an Activity. This is where it can get a bit messy! I'll just post the method and won't bother going into detail as you're probably not interested. If you are, there are plenty of info if you google around a bit.
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CONTACTPICKER) { if(resultCode == RESULT_OK) { Uri contentUri = data.getData(); String contactId = contentUri.getLastPathSegment(); Cursor cursor = getContentResolver().query( Phone.CONTENT_URI, null, Phone._ID + "=?", // < - Note, not CONTACT_ID! new String[]{contactId}, null); startManagingCursor(cursor); Boolean numbersExist = cursor.moveToFirst(); int phoneNumberColumnIndex = cursor.getColumnIndex(Phone.NUMBER); String phoneNumber = ""; while (numbersExist) { phoneNumber = cursor.getString(phoneNumberColumnIndex); phoneNumber = phoneNumber.trim(); numbersExist = cursor.moveToNext(); } stopManagingCursor(cursor); if (!phoneNumber.equals("")) { setPhoneNumber(phoneNumber); } // phoneNumber != "" } // Result Code = RESULT_OK } // Request Code = REQUEST_CONTACTPICER } // end function
Basically what this does is open up the contact phone database at the record with the id of the selected number!
In many cases when browsing for a working solution for this, the problem was this statement at line 11: Phone._ID + "=?", the examples I found had specified it as Phone.CONTACT_ID + "=?" which is used to find a specific contact, not a number.
Unless you've already figured it out, you need a few things for this to work.
1. REQUEST_CONTACTPICKER needs to be specified, something like this:
2. You need these imports:
That's it.
You might have the best app ever created, or you might have the user friendliest web page in the world. You might even have the most useful piece of shareware ever made and still not making any money.
In this first article about how to design user friendly apps we will discuss the use of Dialogs.
So, what we want is this:
This code could easily be used as a base if you need to call a web service that outputs xml
Have you integrated a facebook login to your site, or are you planning to? There\'s a small bug involving the sign in process that can make your life miserable unless you know how to get around it. Here\'s one possible solution.
This Immerse headset from ThumbsUp offers both positive and negative sides.
You might have the best app ever created, or you might have the user friendliest web page in the world. You might even have the most useful piece of shareware ever made and still not making any money.
According to an email DroidXplorer will be preinstalled on devices, and be featured on a set of app stores. For free.