Sending message through WhatsApp By intent

一曲冷凌霜 提交于 2019-11-27 13:21:53
Abdullah AlHazmy

this is a Solution :

private void openWhatsApp(String id) {

Cursor c = getSherlockActivity().getContentResolver()
            .query(ContactsContract.Data.CONTENT_URI,
                  new String[] { ContactsContract.Contacts.Data._ID },  
                  ContactsContract.Data.DATA1 + "=?",
                  new String[] { id }, 
                  null);

c.moveToFirst();
Intent i = new Intent(Intent.ACTION_VIEW, 
              Uri.parse(
                   "content://com.android.contacts/data/" +           
                    c.getString(0)));

startActivity(i);
c.close();
}

Where id is what's app uri like 966123456789@s.whatsapp.net

you can use this code for sending data to perticuler a number

void openWhatsappContact(String number) {
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");  
startActivity(Intent.createChooser(i, ""));}

thats realy works for me enjoy your code:)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!