Android: How to send message programmatically by using WhatsApp, WeChat?

前端 未结 5 1561
情歌与酒
情歌与酒 2020-12-02 17:58

How to use messaging in android application by using WhatsApp and WeChat?

Actually requirement is to send sms using WhatsApp and We

5条回答
  •  孤城傲影
    2020-12-02 18:25

    This is the simplest example that I get

    /**
     * sends message to the specific application
     * @param text The message that user wants to send
     * @param view is the activity view of the application
     */
    public void sendMessage(String text, View view){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setType("text/plain");
        intent.setPackage("com.example.appname");//For whatsapp you can use com.whatsapp
        if (intent !=null){
            intent.putExtra(Intent.EXTRA_TEXT, text);
            startActivity(intent);
        }else{
            Snackbar.make(this, "Application not found.", Snackbar.LENGTH_SHORT).show();
        }
    }
    

提交回复
热议问题