How to open Whatsapp group by clicking a button?

岁酱吖の 提交于 2019-12-31 03:27:05

问题


I made a simple phone directory and was able to open the Whatsapp contacts by clicking a button.

Here is the sample code:

Intent intentWhatsapp = new Intent("android.intent.action.MAIN");
intentWhatsapp.setAction(Intent.ACTION_VIEW);
String url = "https://api.whatsapp.com/send?phone=" + "90xxxxxxxx";
intentWhatsapp.setData(Uri.parse(url));
intentWhatsapp.setPackage("com.whatsapp");
startActivity(intentWhatsapp);}

How can I open the Whatsapp group by clicking a button in android?

Hope to give me any suggestions!


回答1:


You have to use group link. When the user install your app, you should ask them to copy the group link from the whatsapp group info, then you store it to access that group directly from your app. This link is only visible by groups admins, so if the user isn't admin, you should instruct them to ask the link from the admin. Although this link was intended by whatsapp for invitation to groups, it makes the job of opening the desired group chat.

Intent intentWhatsapp = new Intent(Intent.ACTION_VIEW);
String url = "https://chat.whatsapp.com/<group_link>";
intentWhatsapp.setData(Uri.parse(url));
intentWhatsapp.setPackage("com.whatsapp");
startActivity(intentWhatsapp);


来源:https://stackoverflow.com/questions/48457523/how-to-open-whatsapp-group-by-clicking-a-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!