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");
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?
source share