0

I want to make an application where if I click some button, it will send a message on 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?

theduck
  • 2,589
  • 13
  • 17
  • 23
  • I don't think it is possible with regular WA only in WA business.... this may help https://developers.facebook.com/docs/whatsapp/getting-started/ – Pemba Tamang Dec 04 '19 at 06:53

3 Answers3

0

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.

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

Raka Adi Nugroho
  • 3,403
  • 1
  • 8
  • 6
0

You can not do it without using the intent of the application as its the third party application it has the right to do. you should be able to open the Intent and its up to the user to send it as per the Intent opened or not.

Abdur Rahman
  • 894
  • 1
  • 11
  • 27
pramod_m
  • 184
  • 1
  • 9
0
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.