skip to Main Content

I want to open chooser for both whatsapp and gb-whatsapp so the user can choose any of one from them. This code is only opening whatsapp only.

 Intent intentWhatsapp = new Intent(Intent.ACTION_VIEW);
        String url = "https://chat.whatsapp.com/JPJSkaiqmDu5gLKqUPAfMM";
        intentWhatsapp.setData(Uri.parse(url));
        intentWhatsapp.setPackage("com.whatsapp");
        startActivity(intentWhatsapp);

2

Answers


  1. Chosen as BEST ANSWER

    To handle business whatsapp, GB-Whatsapp and normal whatsapp, the url scheme intent needs to be used, since the normal method of using package "com.whatsapp" only works for normal whatsapp.

    Here's the code sample to handle gb, normal and business whatsapp :

    try {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse("whatsapp://send?phone="+ "+92300xxxxxxx" +"&text=" + URLEncoder.encode("Messagen", "UTF-8")));
        context.startActivity(i);
    } catch (Exception e){
        Toast.makeText(context, "Whatsapp not installed!", Toast.LENGTH_LONG).show();
    }
    

  2. Simple answer you can’t.
    More detailed answer: You can only create an Intent targeting one specific app. I would suggest building a dialogue inside your app, showing the app images of whatsapp and gb-whatsapp, and then putting specific intents behind those two images so that it "looks" like the Android chooser.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search