gpt4 book ai didi

java - 如何在android studio中的whatsapp上自动发送消息

转载 作者:行者123 更新时间:2023-12-01 17:45:09 25 4
gpt4 key购买 nike

点击onclick按钮时如何自动发送whatsapp消息

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

最佳答案

不知道是不是你想要的样子。我相信这是一种做法。试试这个。

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

关于java - 如何在android studio中的whatsapp上自动发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60876488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com