how to open whatsapp or whatsapp business with intent android studio?

Viewed 2126

I'm using this code, and it opens WhatsApp, but it doesn't allow me to open WhatsApp business, is there any way to verify which WhatsApp the user has installed?

String contact = phone;
Double amount_total = pac_val_amo + del_fac_amo;
String total = "S/. " + String.format("%.2f", amount_total);
String message = "Su pedido de " + store + " ha llegado, su pago total es de S/. " + total;
String url = "https://api.whatsapp.com/send?phone=" + contact + "&text=" + message;
try {
    PackageManager pm = getContext().getPackageManager();
    pm.getPackageInfo("com.whatsapp", PackageManager.GET_ACTIVITIES);
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);
    } catch (PackageManager.NameNotFoundException e) {
           Toast.makeText(getContext(), "WhatsApp is not installed on this Device.", Toast.LENGTH_SHORT).show();
    e.printStackTrace();
    }
1 Answers

You can open whatsapp business by using its package name com.whatsapp.w4b

Just do an if else check between com.whatsapp and com.whatsapp.w4b before starting the intent

Related