简体   繁体   English

使用 Android java 在 WhatsApp 上自动发送消息?

[英]Automatic message send on WhatsApp with Android java?

I want to make an application where if I click some button, it will send a message on whatsapp.我想做一个应用程序,如果我单击某个按钮,它将在 whatsapp 上发送一条消息。 I have already enter message and cellphone numbers with :我已经输入了消息和手机号码:

String nomor = hp.getText().toString();
String message = "Hallo";

startActivity(new Intent(Intent.ACTION_VIEW,
                         Uri.parse(
                            String.format("https://api.whatsapp.com/send?phone=%s&text=%s",
                            nomor, message))));

The problem is that it does not auto send, so we must push the send button... Anybody can help me?问题是它不会自动发送,所以我们必须按下发送按钮......有人可以帮助我吗?

Maybe your question is how to make the function of sending messages directly and quietly (in the background), that can't be可能你的问题是如何让直接悄悄地(在后台)发送消息的功能,那不能

action.VIEW is run in foreground, and when you access the applink with the whatsapp scheme, then the full rights are the property of the whatsapp application. action.VIEW 是在前台运行的,当你使用 whatsapp 方案访问 applink 时,完全权限是 whatsapp 应用程序的财产。

ref: https://developer.android.com/reference/android/content/Intent参考: https : //developer.android.com/reference/android/content/Intent

You can not do it without using the intent of the application as its the third party application it has the right to do.如果不使用applicationintent ,您就不能这样做,因为它是它有权做的第三方application you should be able to open the Intent and its up to the user to send it as per the Intent opened or not.您应该能够打开 Intent 并由用户根据是否打开 Intent 发送它。

PackageManager pm=getPackageManager();
try {
    Intent waIntent = new Intent(Intent.ACTION_SEND);
    waIntent.setType("text/txt");

    PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
    waIntent.putExtra("jid", *NUMBER* + "@s.whatsapp.net");
    waIntent.setPackage("com.whatsapp");
    Uri uri = Uri.parse( String.format("https://api.whatsapp.com/sendphone=%s&text=%s",
                        nomor, message));
    waIntent.putExtra(Intent.EXTRA_STREAM,uri);
    startActivity(Intent.createChooser(waIntent, "Share with"));               
} catch (PackageManager.NameNotFoundException e) {
    //error message
}

This code sends a message to the specified number.此代码向指定号码发送消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM