Android Question How to open chat with WhatsApp for Business number?

asales

Expert
Licensed User
Longtime User
I use this excellent WhatsApp library from @MarcoRome , but (until this moment) it don't works with WhatsApp for Business.

I want to recreate the original code from the library to open chat with the contact in the WhatsApp Business.

I tried to make this, but don't works:
B4X:
Sub OpenChatWithNumberW4b(numphone As String)
    Dim i As Intent
    i.Initialize("android.intent.action.SENDTO", "smsto:" & numphone)
    Dim jo As JavaObject = i
    jo.RunMethod("setPackage", Array("com.whatsapp.w4b"))
    StartActivity(i)
End Sub
This is the original code from library:
B4X:
/**
* Open Chat with Number
*Example:<code>
*Dim whapp As WhatsApp
*whapp.OpenChatWithNumber("+39334336444")</code>
*/    
    private final static String WHATSSAP_APP_ID = "com.whatsapp";

    public void OpenChatWithNumber(BA ba, String phoneNumber) {
        try{
            Uri uri = Uri.parse("smsto:" + phoneNumber);
            Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
            intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setPackage(WHATSSAP_APP_ID); 
            ba.context.startActivity(intent);
        }catch(Exception e){
            if(DEBUG) Log.e("Exception", e.toString());
            int duration = Toast.LENGTH_LONG;

            Toast toast = Toast.makeText(ba.context, e.toString(), duration);
            toast.show();
        }
    }
Thanks in advance for any tips.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top