Home > front end >  How to link my app with WhatsApp when WhatsApp Business is also on the device?
How to link my app with WhatsApp when WhatsApp Business is also on the device?

Time:10-10

WhatsApp Business opens in place of WhatsApp. How can I link only to WhatsApp? Here is the code:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send phone=" phonestr "&text=" messagestr));

startActivity(i);
               

CodePudding user response:

You can set the target package (application ID) that you want to handle the intent using Intent.setPackage. But if the package is not installed it will throw an exception so keep in mind to handle that as well.

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send phone=" phonestr "&text=" messagestr));

i.setPackage("com.whatsapp");

startActivity(i);
               

In addition you can try different packages after getting ActivityNotFound exception. For example try WhatsApp and if it threw an Exception, then try WhatsApp Business or whatever

  • Related