after long Googleing which didn't brought the result I hoped it would, I have two questions about accessing WhatsApp from another Android app.
First of all I want to explain my current development status:
Wrote an app with which you can share some text via WhatsApp. The app is exactly doing what it is supposed to do (as I am completely new to Android development). The first way I found was described in WhatsApp's "FAQ for Android developers". It creates a new intent, prefills the text which should be send and opens the contact picker:
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 prefill it with the text I want to share:
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 a WhatsApp group?
- Can I open the group chat and paste my text just with replacing the phone number in method 2 by the group ID? Or is there another way to open and prefill a group chat?
i use Tasker to get the group's jid, especially the group that i'm NOT the admin of. you need to do it manually. so if you have 10 groups, you will need to do it 10 times. create a task in tasker, click app, click shortcut, click the magnifying glass, search for the group, click the group, the jid will be shown inside the long string. it should end with %40 so extract the jid manually