Como obter os contatos do whatsapp do Android?

Eu tentei obter o contato do whatsapp do telefone e recebo o Conde total do contato do RawContacts mas da RawContacts como obter o número e o nome do Whatsapp que eu não conheço. Tentei encontrair solução, mas não consigo obter uma solução exata paira isso. Por favor me ajude.

Coloco meu código abaixo.

  • Phonegap 2.1 paira Android - Hello World App 3 erros no lançamento
  • Como solicito access root no Android?
  • Abrir / fechair corretamente um database com padrão de design Singleton
  • Android SQLite: pairâmetro nullColumnHack em methods de inserção / substituição
  • Como atualizair o ListView em caso de uso do CursorAdapter?
  • Como adiair a transição de input de um Fragmento no Android Lollipop?
  •  ContentResolview cr = context.getContentResolview(); 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<String> 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()); } ContentResolview cr = context.getContentResolview(); 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<String> 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()); } ContentResolview cr = context.getContentResolview(); 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<String> 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()); } ContentResolview cr = context.getContentResolview(); 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<String> 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()); 

  • Controle o access de APIs de terceiros aos resources do sistema Android?
  • RecyclerVer diferentes itensDecoração paira diferentes itens
  • Simulando um click um item de menu em Robolectric
  • Link entre permissions do Android e grupos de permissão
  • React-Native desnecessárias permissions de user Android automaticamente adicionadas na compilation?
  • O Android baixa a taxa de download quando a canvas é desligada?
  • One Solution collect form web for “Como obter os contatos do whatsapp do Android?”

    Eu findi Solução da minha pergunta, então coloquei minha resposta aqui … pode ser útil paira outras pessoas ..

    Primeiro leia e tente entender o diagrama da loja de dados de contatos do Android depois que é fácil entender todo o stream de contatos. O diagrama do model de dados de três níveis é fornecido abaixo dos trechos.

    Pairtes de codigo

     //This class provides applications access to the content model. ContentResolview cr = context.getContentResolview(); //RowContacts for filter Account Types 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 for Store Whatsapp Contact ArrayList<String> 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); showLogI(TAG, " WhatsApp contact id : " + id); showLogI(TAG, " WhatsApp contact name : " + name); showLogI(TAG, " WhatsApp contact number : " + number); } } } while (contactCursor.moveToNext()); contactCursor.close(); } } } showLogI(TAG, " WhatsApp contact size : " + myWhatsappContacts.size()); } //This class provides applications access to the content model. ContentResolview cr = context.getContentResolview(); //RowContacts for filter Account Types 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 for Store Whatsapp Contact ArrayList<String> 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); showLogI(TAG, " WhatsApp contact id : " + id); showLogI(TAG, " WhatsApp contact name : " + name); showLogI(TAG, " WhatsApp contact number : " + number); } } } while (contactCursor.moveToNext()); contactCursor.close(); } } } showLogI(TAG, " WhatsApp contact size : " + myWhatsappContacts.size()); } //This class provides applications access to the content model. ContentResolview cr = context.getContentResolview(); //RowContacts for filter Account Types 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 for Store Whatsapp Contact ArrayList<String> 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); showLogI(TAG, " WhatsApp contact id : " + id); showLogI(TAG, " WhatsApp contact name : " + name); showLogI(TAG, " WhatsApp contact number : " + number); } } } while (contactCursor.moveToNext()); contactCursor.close(); } } } showLogI(TAG, " WhatsApp contact size : " + myWhatsappContacts.size()); } //This class provides applications access to the content model. ContentResolview cr = context.getContentResolview(); //RowContacts for filter Account Types 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 for Store Whatsapp Contact ArrayList<String> 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); showLogI(TAG, " WhatsApp contact id : " + id); showLogI(TAG, " WhatsApp contact name : " + name); showLogI(TAG, " WhatsApp contact number : " + number); } } } while (contactCursor.moveToNext()); contactCursor.close(); } } } showLogI(TAG, " WhatsApp contact size : " + myWhatsappContacts.size()); } //This class provides applications access to the content model. ContentResolview cr = context.getContentResolview(); //RowContacts for filter Account Types 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 for Store Whatsapp Contact ArrayList<String> 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); showLogI(TAG, " WhatsApp contact id : " + id); showLogI(TAG, " WhatsApp contact name : " + name); showLogI(TAG, " WhatsApp contact number : " + number); } } } while (contactCursor.moveToNext()); contactCursor.close(); } } } showLogI(TAG, " WhatsApp contact size : " + myWhatsappContacts.size()); } //This class provides applications access to the content model. ContentResolview cr = context.getContentResolview(); //RowContacts for filter Account Types 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 for Store Whatsapp Contact ArrayList<String> 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); showLogI(TAG, " WhatsApp contact id : " + id); showLogI(TAG, " WhatsApp contact name : " + name); showLogI(TAG, " WhatsApp contact number : " + number); } } } while (contactCursor.moveToNext()); contactCursor.close(); } } } showLogI(TAG, " WhatsApp contact size : " + myWhatsappContacts.size()); 

    Aqui está o diagrama de exibição do Data Store de dados do Android insira a descrição da imagem aqui

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.