Wie erhalte ich programmgesteuert WhatsApp-Kontakte von Android?Android

Forum für diejenigen, die für Android programmieren
Anonymous
 Wie erhalte ich programmgesteuert WhatsApp-Kontakte von Android?

Post by Anonymous »

Ich muss versuchen, WhatsApp-Kontakte vom Telefon abzurufen, und erhalte die Gesamtzahl der WhatsApp-Kontakte, aber von RawContacts, wie ich WhatsApp-Nummern und -Namen erhalte, die ich nicht kenne. Ich habe versucht, eine Lösung zu finden, kann aber nicht die genaue Lösung dafür finden. Bitte helfen Sie mir.
Ich füge meinen Code unten ein.

Code: Select all

ContentResolver cr = context.getContentResolver();

Cursor c = cr.query(
ContactsContract.RawContacts.CONTENT_URI,
new String[] { ContactsContract.RawContacts.CONTACT_ID, ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY },
ContactsContract.RawContacts.ACCOUNT_TYPE + "= ?",
new String[] { "com.whatsapp" },
null);

ArrayList myWhatsappContacts = new ArrayList();

String projection[] = { ContactsContract.CommonDataKinds.Phone.NUMBER };

if(c != null) {
if (c.getCount() > 0) {
while (c.moveToNext()) {

String whatsappContactId = c.getString(c.getColumnIndex(ContactsContract.RawContacts.Data._ID));

Cursor dataCursor = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
projection,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{whatsappContactId}, null);
// You can also read RawContacts.CONTACT_ID to read the
// ContactsContract.Contacts table or any of the other related ones.
String number = dataCursor.getString(dataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER));
myWhatsappContacts.add(number);

}
}
}

showLogI(TAG, " WhatsApp contact size :  " + myWhatsappContacts.size());

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post