How to get numbers from contacts in android?

Get contacts in Android

  • I want to get the contact numbers in Android but as far as I found a tutorial, it puts out the number in ascending order, not in the order they appear in the contacts... How can I modify the code to obtain the numbers in the exact order from my contact list?? Cursor cursor = getContentResolver().query(Phone.CONTENT_URI, new String[]{Phone.NUMBER}, null,null, null); ArrayList <String> nr_formatat = new ArrayList <String> (); if (cursor != null) { while (cursor.moveToNext() == true) nr_formatat.add(cursor.getString( cursor.getColumnIndex(Phone.NUMBER))); }

  • Answer:

    You're going about it the wrong way. You need to query the number against the CONTACT_ID or else you won't have any correspondence between the two. Take a look at http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/.

Madrugada at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

It depends on how your contacts are ordered in your contact list. Hit the menu button and tap on 'Display Options'. Other than that, you don't have enough information in your question to adequately answer it. From what I can see, you're going about it the wrong way. I would look over this example application. It fetches the contacts differently than you and will allow you to sort it however you want. http://developer.android.com/resources/samples/BusinessCard/src/com/example/android/businesscard/index.html

Trev

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.