Send message to specific contact through whatsapp from another app

前端 未结 6 2311
无人共我
无人共我 2021-02-20 07:58

Is it possible to send message to a specific contact through whatsapp directly from another app? I know the contact ID. I don\'t want to open whatsapp

6条回答
  •  不知归路
    2021-02-20 08:56

    Please try this,

    public void onClickWhatsApp(View view) {
    
    Intent waIntent = new Intent(Intent.ACTION_SEND);
    waIntent.setType("text/plain");
            String text = "YOUR TEXT HERE";
    waIntent.setPackage("com.whatsapp");
    if (waIntent != null) {
        waIntent.putExtra(Intent.EXTRA_TEXT, text);//
        startActivity(Intent.createChooser(waIntent, "Share with"));
    } else {
        Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
                .show();
    }
    }
    

    Source : Please check this answer for further details

提交回复
热议问题