Permissions
<uses-permission android:name="android.permission.READ_CONTACTS"/>
JavaFunction
private ArrayList<Map<String, String>> fetchWhatsAppContacts(){
ArrayList<Map<String, String>> list = new ArrayList<Map<String,String>>();
final String[] projection={
ContactsContract.Data.CONTACT_ID,
ContactsContract.Data.MIMETYPE,
"account_type",
ContactsContract.Data.DATA3,
};
final String selection= ContactsContract.Data.MIMETYPE+" =? and account_type=?";
final String[] selectionArgs = {
"vnd.android.cursor.item/vnd.com.whatsapp.profile",
"com.whatsapp"
};
ContentResolver cr = getContentResolver();
Cursor c = cr.query(
ContactsContract.Data.CONTENT_URI,
projection,
selection,
selectionArgs,
null);
while(c.moveToNext()){
String id=c.getString(c.getColumnIndex(ContactsContract.Data.CONTACT_ID));
String number=c.getString(c.getColumnIndex(ContactsContract.Data.DATA3));
number=number.replace("Message ", "");
String name="";
Log.w("number",number);
Cursor mCursor=getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI,
new String[]{ContactsContract.Contacts.DISPLAY_NAME},
ContactsContract.Contacts._ID+" =?",
new String[]{id},
null);
while(mCursor.moveToNext()){
name=mCursor.getString(mCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
}
mCursor.close();
list.add(putData(name, number));
}
Log.w("WhatsApp", "Total WhatsApp Contacts: "+c.getCount());
Log.w("Listdata",list.toString());
c.close();
return list;
}
<uses-permission android:name="android.permission.READ_CONTACTS"/>
JavaFunction
private ArrayList<Map<String, String>> fetchWhatsAppContacts(){
ArrayList<Map<String, String>> list = new ArrayList<Map<String,String>>();
final String[] projection={
ContactsContract.Data.CONTACT_ID,
ContactsContract.Data.MIMETYPE,
"account_type",
ContactsContract.Data.DATA3,
};
final String selection= ContactsContract.Data.MIMETYPE+" =? and account_type=?";
final String[] selectionArgs = {
"vnd.android.cursor.item/vnd.com.whatsapp.profile",
"com.whatsapp"
};
ContentResolver cr = getContentResolver();
Cursor c = cr.query(
ContactsContract.Data.CONTENT_URI,
projection,
selection,
selectionArgs,
null);
while(c.moveToNext()){
String id=c.getString(c.getColumnIndex(ContactsContract.Data.CONTACT_ID));
String number=c.getString(c.getColumnIndex(ContactsContract.Data.DATA3));
number=number.replace("Message ", "");
String name="";
Log.w("number",number);
Cursor mCursor=getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI,
new String[]{ContactsContract.Contacts.DISPLAY_NAME},
ContactsContract.Contacts._ID+" =?",
new String[]{id},
null);
while(mCursor.moveToNext()){
name=mCursor.getString(mCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
}
mCursor.close();
list.add(putData(name, number));
}
Log.w("WhatsApp", "Total WhatsApp Contacts: "+c.getCount());
Log.w("Listdata",list.toString());
c.close();
return list;
}
Comments
Post a Comment