mardi 22 septembre 2015

How can i get only all mobile numbers from android phone book ?

that's my code , which give me all no of my android device like mobile numbers, whatsapp no and landline numbers. but i want only mobile no and landline numbers from android phone book into my application. how can i get only mobile no and landline no of every contact name ...

thanks in advance.....

private void addContactsInList() { // TODO Auto-generated method stub

    Cursor cursor = getContentResolver().query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
            null, null, null, null);

    try {
        ContactsListClass.phoneList.clear();
    } catch (Exception e) {

    }

    while (cursor.moveToNext()) {
        String phoneName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
        String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        int phoneId = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));


        Contact cp = new Contact();

        cp.setName(phoneName);
        cp.setNumber(phoneNumber);
        cp.setId(phoneId);


        ContactsListClass.phoneList.add(cp);
       // Log.e("add to list", "content" + phoneId +phoneName +phoneNumber);
    }
    cursor.close();

    lv = new ListView(context);

    lv.setLayoutParams(new LayoutParams(
            LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT));


    llContainer.addView(lv);

    Collections.sort(ContactsListClass.phoneList, new Comparator<Contact>() {
        @Override
        public int compare(Contact lhs,
                           Contact rhs) {
            return lhs.getName().compareTo(
                    rhs.getName());
        }
    });

    contactAdapter = new ContactsAdapter(MainActivity.this,
            ContactsListClass.phoneList);
    lv.setAdapter(contactAdapter);

Aucun commentaire:

Enregistrer un commentaire