How to open both WhatsApp and GB-Whatsapp using an Intent in your Android App
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("Message\n", "UTF-8")));
context.startActivity(i);
} catch (Exception e){
Toast.makeText(context, "Whatsapp not installed!", Toast.LENGTH_LONG).show();
}
Sending message through WhatsApp
UPDATE
Please refer to https://faq.whatsapp.com/en/android/26000030/?category=5245251
WhatsApp's Click to Chat feature allows you to begin a chat with
someone without having their phone number saved in your phone's
address book. As long as you know this person’s phone number, you can
create a link that will allow you to start a chat with them.Use: https://wa.me/15551234567
Don't use: https://wa.me/+001-(555)1234567
Example: https://wa.me/15551234567?text=I'm%20interested%20in%20your%20car%20for%20sale
Original answer
Here is the solution
public void onClickWhatsApp(View view) {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
Also see http://www.whatsapp.com/faq/en/android/28000012
How to open Whatsapp from other app
Did you try this
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.whatsapp");
startActivity(launchIntent);
Related Topics
How to Display a Pdf Via Android Web Browser Without "Downloading" First
Http Failure Response for (Unknown Url): 0 Unknown Error on Android
How to Verify Purchase for Android App in Server Side (Google Play in App Billing V3)
Error Androidmanifest.Xml Doesn't Exist or Has Incorrect Root Tag
How to Access Data/Data Folder in Android Device
How to Place an Imageview on Top of Another Imageview in Android
Remove Green Border Around Android Application
Download a File Programmatically on Android
Android Edittext Text Control - How to Disable Possibility to Insert Gif from Google Keyboard
Download Failed Because the Resources Could Not Be Found
Android Fastboot Waiting for Devices
Java.Io.Ioexception: Permission Denied Cannot Create File
Access Ro.Serialno from Native in Android 8
Android Force Gpu Rendering How to Enable and Disable
Asking Camera Permission for Webview At Runtime
Android Compress Video Before Upload to Server
How to Retry Retrofit Call on Http Errors (401) When Using Rxjava