Opening Whatsapp with intent is not working in android OS 11 but working fine up to android (OS) 10 devices, It displays the message "Whatsapp app not installed in your phone" on the android 11 device. Does anyone have a solution for this?
String contact = "+91 9999999999"; // use country code with your phone number
String url = "https://api.whatsapp.com/send?phone=" + contact;
try {
PackageManager pm = context.getPackageManager();
pm.getPackageInfo("com.whatsapp", PackageManager.GET_ACTIVITIES);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
context.startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(mContext, "Whatsapp app not installed in your phone",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker: Intent sendIntent = new Intent(); sendIntent.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken button view to open YouTube application.
There are new changes in android 11 of package visibility.
You need to add a new section under you app's <manifest>
tag:
<queries>
<package android:name="com.whatsapp" />
</queries>
"com.whatsapp"
can also be the culprit.
i was also boggled with this message.
the issue was "whatsApp business app" which has package name:"com.whatsapp.w4b"
used following code to find out which one is installed:
String appPackage="";
if (isAppInstalled(ctx, "com.whatsapp.w4b")) {
appPackage = "com.whatsapp.w4b";
//do ...
} else if (isAppInstalled(ctx, "com.whatsapp")) {
appPackage = "com.whatsapp";
//do ...
} else {
Toast.makeText(ctx, "whatsApp is not installed", Toast.LENGTH_LONG).show();
}
private boolean isAppInstalled(Context ctx, String packageName) {
PackageManager pm = ctx.getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With