0

I want to get all the mobile numbers and details(forexample operator name) of each mobile number stored in my Android device.and display in ListView ,Any Idea how can achieve this?

kavie
  • 2,154
  • 4
  • 28
  • 53
  • You can look here : http://stackoverflow.com/questions/16124034/how-to-retrieve-the-list-of-contacts-in-android?rq=1 – Farouk Touzi Jul 24 '14 at 13:51

1 Answers1

1

You can try this:

public class MainActivity extends Activity {

    @Override
    protected void onCreate( final Bundle savedInstanceState ) {

        this.getAllMobileNumbers( this );

        super.onCreate( savedInstanceState );
    }

    private ArrayList<String> getAllMobileNumbers( final Context context ) {
        final ArrayList<String> listNumbers = new ArrayList<String>();
        final Cursor cursor = context.getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null );
        while ( cursor.moveToNext() ) {
            final int phone_id = cursor.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER );
            final String phone = cursor.getString( phone_id );
            listNumbers.add( phone );
        }

        return listNumbers;
    }

}
wbelarmino
  • 509
  • 3
  • 7