Android - WhatsApp Group ID / Open Group Chat

after a long googleing that failed to produce a result, I was hoping that I would have two questions about accessing WhatsApp from another Android app.

First of all, I want to explain my current development status:

Wrote an application with which you can share some text through WhatsApp. The app does exactly what it should do (since I'm completely new to Android development). The first method I found was described in WhatsApp "FAQ for Android Developers". He creates a new intention, pre-fills the text to be sent, and opens the contact selection panel:

int pos = 0; //0 is just an example value Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); PushAlert pa = pushAlerts.get(pos); //get my text object from ArrayList sendIntent.setPackage("com.whatsapp"); //directly choose WhatsApp as sharing app sendIntent.putExtra(Intent.EXTRA_TEXT, "*" + pa.getTitle() + " * \n +" + pa.getContent()); //filling sendIntent.setType("text/plain"); startActivity(sendIntent); //Open contact picker 

Googled and googled, so I found a way (code snippet) to open a specific personal chat and fill it with the text I want to provide:

 private void openWhatsAppChat(){ Intent sendIntent = new Intent("android.intent.action.SEND"); sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.ContactPicker")); sendIntent.setType("text"); sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("phone number")+"@s.whatsapp.net"); //number without '+' prefix and without '0' after country code sendIntent.putExtra(Intent.EXTRA_TEXT,"sample text you want to send along with the image"); startActivity(sendIntent); } 

So my questions are:

  • How can I get the WhatsApp ID of the WhatsApp group?
  • Can I open a group chat and insert my text only with the replacement of the phone number in method 2 with the group ID? Or is there another way to open and fill out group chat?
+5
source share
1 answer

You must use a group link.
When the user installs your application, you should ask them to copy the link to the group from the information about the whatsapp group, and then save it to access this group directly from the application.
This link is visible only to group administrators, so if the user is not an administrator, you should ask them to request a link from the administrator.
Although this link was designed by whatsapp for inviting groups, it does 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); 
+1
source

Source: https://habr.com/ru/post/1263935/


All Articles