简体   繁体   中英

how to auto send message on whatsapp in android studio

how when clicked onclick button whatsapp messages can be sent automatically

  public void onclick(){

     boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp");
     if (isWhatsappInstalled) {
          Uri uri = Uri.parse("smsto:" + "628124291xxxx");

          Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);    
          sendIntent.putExtra(Intent.EXTRA_TEXT, "hallo");
          sendIntent.setPackage("com.whatsapp");
          startActivity(sendIntent);
      } else {
          Toast.makeText(MainActivity.this, "WhatsApp not Installed",
          Toast.LENGTH_SHORT).show();
          Uri uri = Uri.parse("market://details?id=com.whatsapp");
          Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
          startActivity(goToMarket);
      }
  }

I don't know if it's the way you want it.I believe it is a way of doing. Try this.

String toNumber = "628124291xxxx";
String url = "https://api.whatsapp.com/send?phone="+ toNumber;

Intent i = new Intent(Intent.ACTION_VIEW);
i.setPackage("com.whatsapp"); //com.whatsapp or com.whatsapp.w4b
i.setData(Uri.parse(url));
startActivity(i);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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