我想获得whatsApp profilepicture但只获取名称和contactnumber?

我想获取WhatsApp个人资料图片和编号,但是使用contentResolver我将使用以下代码段获取名称和编号。

private void showContactWhatsApp(){ ContentResolver cr = getContentResolver(); Cursor contactCursor = cr.query( ContactsContract.RawContacts.CONTENT_URI, new String[]{ContactsContract.RawContacts._ID, ContactsContract.RawContacts.CONTACT_ID}, ContactsContract.RawContacts.ACCOUNT_TYPE + "= ?", new String[]{"com.whatsapp"}, null); ArrayList myWhatsappContacts = new ArrayList(); if (contactCursor != null) { if (contactCursor.getCount() > 0) { if (contactCursor.moveToFirst()) { do { //whatsappContactId for get Number,Name,Id ect... from ContactsContract.CommonDataKinds.Phone String whatsappContactId = contactCursor.getString(contactCursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID)); if (whatsappContactId != null) { //Get Data from ContactsContract.CommonDataKinds.Phone of Specific CONTACT_ID Cursor whatsAppContactCursor = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.Phone.CONTACT_ID, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME}, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{whatsappContactId}, null); if (whatsAppContactCursor != null) { whatsAppContactCursor.moveToFirst(); String id = whatsAppContactCursor.getString(whatsAppContactCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID)); String name = whatsAppContactCursor.getString(whatsAppContactCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); String number = whatsAppContactCursor.getString(whatsAppContactCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); whatsAppContactCursor.close(); //Add Number to ArrayList myWhatsappContacts.add(number); Log.e(TAG, " WhatsApp contact id : " + id); Log.e(TAG, " WhatsApp contact name : " + name); Log.e(TAG, " WhatsApp contact number : " + number); } } } while (contactCursor.moveToNext()); contactCursor.close(); } } } Log.e(TAG, " WhatsApp contact size : " + myWhatsappContacts.size()); } 

我想获得像SyncMe应用程序的WhatsApp个人资料图片。

我等着获得WhatsApp联系人列表,其中包含姓名,号码和缩略图。

Related of "我想获得whatsApp profilepicture但只获取名称和contactnumber?"

首先,我只想重申RawContactContact之间的RawContact 。 后者是前者(代表一个帐户)的聚合(代表一个人)。

根据您对图像的用途,最好是获取聚合联系人并使用在那里选择的配置文件图像,这可以通过Photo合同实现。

 Uri photoUri; Cursor photoCur = cr.query( ContactsContract.Data.CONTENT_URI, null, ContactsContract.Data.CONTACT_ID + "=" + aggregateContactId + " AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'", null, null ); if (photoCur != null && photoCur.moveToFirst()) { Uri photoId = ContentUris.withAppendedId(Contacts.CONTENT_URI, aggregateContactId); photoUri = Uri.withAppendedPath(person, Contacts.Photo.CONTENT_DIRECTORY); } 

如果你专门用于WhatsApp照片,首先要确保照片缓存在设备上(只是为了避免测试时出现错误的标记 – 在WhatsApp中打开联系人完整图像,你可以确定它已被缓存)然后你必须对图像进行单独查找(来自API 14):

 Uri photoId = ContentUris.withAppendedId(RawContacts.CONTENT_URI, whatsappContactId); Uri photoUri = Uri.withAppendedPath(photoId, RawContacts.DisplayPhoto.CONTENT_DIRECTORY);