Sending message through WhatsApp

前端 未结 23 2682
萌比男神i
萌比男神i 2020-11-22 09:42

Since I found some older posts, that tell that whatsapp doesn\'t support this, I was wondering if something had changed and if there is a way to open a whatsapp \'chat\' wit

23条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 10:32

    get the contact number whom you want to send the message and create uri for whatsapp, here c is a Cursor returning the selected contact.

    Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
    i.setType("text/plain");
    i.setPackage("com.whatsapp");           // so that only Whatsapp reacts and not the chooser
    i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
    startActivity(i);
    

提交回复
热议问题