How to share text to WhatsApp from my app?

前端 未结 9 1221
醉话见心
醉话见心 2020-12-04 12:27

I develop an app with a functionality for sharing text. This is working fine except for WhatsApp. What should I do? Is there any specific API for that?

9条回答
  •  鱼传尺愫
    2020-12-04 12:39

    You can use intent to do so. No need to use Whatsapp API. Hope that I have not misunderstood your question. Hope that helps, thanks.

    Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
    whatsappIntent.setType("text/plain");
    whatsappIntent.setPackage("com.whatsapp");
    whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
    try {
        activity.startActivity(whatsappIntent);
    } catch (android.content.ActivityNotFoundException ex) {
        ToastHelper.MakeShortText("Whatsapp have not been installed.");
    }
    

提交回复
热议问题