首页 > 解决方案 > Whatsapp 自动发送消息而无需单击 android 上的发送按钮

问题描述

我已经在互联网上搜索了很长时间,但仍然找不到自动发送消息的方法。到目前为止,我的应用程序可以做的是向某个联系人打开 Whatsapp 并写下我要发送的消息。这是我的代码:

此代码用于检查设备上是否安装了 Whatsapp

private boolean checkWA(String uri) {
        PackageManager packageManager = getPackageManager();
        boolean appInstalled;

        try {
            packageManager.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            appInstalled = true;
        }
        catch (PackageManager.NameNotFoundException e) {
            appInstalled = false;
        }
        return  appInstalled;
    }

此代码旨在 Whatsapp(无法自动发送消息)

public void onClickWhatsApp() {

        boolean installed = checkWA("com.whatsapp");
        if (installed){
            String url = "https://api.whatsapp.com/send/?phone=6282167975500&text=" + "ADDON ERROR";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setPackage("com.whatsapp");
            i.setData(Uri.parse(url));
            startActivity(i);
        }
        else {
            String url = "https://api.whatsapp.com/send/?phone=6282167975500&text=" + "ADDON ERROR";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    }

有谁知道如何做自动发送部分?谢谢。

标签: javaandroid-studioautomationwhatsappsendmessage

解决方案


推荐阅读