发送WhatsApp的消息,具体的联系具体、消息、WhatsApp

2023-09-04 03:44:05 作者:绝情少女&心已死

我跟着这个link这是我的code

I followed this link and this is my code

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/" + "MYNUMBER@s.whatsapp.net"));
                i.setPackage("com.whatsapp");
                startActivity(i);

这是我的日志

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://com.android.contacts/data/MYNUMBER@s.whatsapp.net pkg=com.whatsapp }
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
        at android.app.Activity.startActivityForResult(Activity.java:3351)
        at android.app.Activity.startActivityForResult(Activity.java:3312)
        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:824)
        at android.app.Activity.startActivity(Activity.java:3522)
        at android.app.Activity.startActivity(Activity.java:3490)
        at com.sieryuu.maidchan.MainActivity.onClick(MainActivity.java:61)
        at android.view.View.performClick(View.java:4147)
        at android.view.View$PerformClick.run(View.java:17161)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:213)
        at android.app.ActivityThread.main(ActivityThread.java:4787)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)

我的问题: 如何文本发送到WhatsApp的背景接触(不选择联系人号码,我已经知道该ID)? 如果需要

My Question : How to send text to whatsapp contact in the background (without choose the contact number, I already know the ID)? Root if needed

推荐答案

在Google上搜寻了一​​点后,我发现下面的code

after googling a little, i found the following code

    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();
    }

}

这样你就可以发送意图发送消息,但据是香港专业教育学院读你不能将其发送给特定联系人

so you can send an intent to send a message, but as far is ive read you cant send it to a specific contact