I want to check that whether whatsapp is installed in mobile or not if installed then show toast "installed" and if not installed then show Toast "Not Installed".How can I do that Kindly help.
Asked
Active
Viewed 1.7k times
16
-
1search by its package name using package manager – Shubham AgaRwal Apr 05 '16 at 07:08
-
Possible duplicate of [Check if application is installed - Android](http://stackoverflow.com/questions/18752202/check-if-application-is-installed-android) – Vipul Asri Apr 05 '16 at 07:17
7 Answers
29
You can use this code. It will check if package is installed.
public class Example extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Put the package name here...
if(isAppInstalled("com.whatsapp")) {
System.out.println("App is already installed on your phone");
} else {
System.out.println("App is not currently installed on your phone");
}
}
private boolean isAppInstalled(String packageName) {
try {
getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
return true;
}
catch (PackageManager.NameNotFoundException ignored) {
return false;
}
}
}

Taha Sami
- 1,565
- 1
- 16
- 43

Eliasz Kubala
- 3,836
- 1
- 23
- 28
-
4
-
i tried this but in Redem note 10 pro max with andriod 11 it goes to catch and the only error message i get is "com.whatsapp". has there some thing changed? – StackOverflower Oct 14 '22 at 15:01
8
based on @eliasz-kubala answer this will work for me on Android 11 after only adding this to Manifest
<manifest
...>
<queries> <package android:name="com.whatsapp" /> </queries>
<application ....>
</application>
</manifest>
and Then use this Kotlin function
private fun isAppInstalled(packageName: String): Boolean {
val pm: PackageManager = getPackageManager()
return try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}
}

Sattar
- 2,453
- 2
- 33
- 47
-
would love to know what's the reason for this. What does query exactly do? And why do we need it. Btw thanks for sharing. – oyeraghib Dec 11 '22 at 14:33
1
This is the code to get all package names of installed applications in device
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
after getting list of packages search for com.whatsapp(package name of whats app given on official webiste Whatsapp). Thats it..

Adeel Turk
- 897
- 8
- 23
0
Try this.
Here you need to pass package name as uri.
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
Check condition like this.
if(!appInstalledOrNot("com.whatsapp")){
// Toast message not installed.
}else{
// Toast message installed.
}

Jay Rathod
- 11,131
- 6
- 34
- 58
0
Try like this:
public class WhatsApp_Check extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
boolean installed = appInstalledOrNot("whatsapp_package_name");
if(installed) {
//print whatsApp is already installed on your phone
else{
// print whatsApp is not currently installed on your phone
}
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
}

Saurabh Vardani
- 1,821
- 2
- 18
- 33
0
Try this method:
private void checkWhatsapp() {
String packageName = "com.whatsapp";
String mesgToShare = "Hey, I am searching for Whatsapp in your device.";
boolean gotPackage = false;
Intent shareIntent = new Intent( android.content.Intent.ACTION_SEND );
shareIntent.setType( "text/plain" );
shareIntent.putExtra( android.content.Intent.EXTRA_TEXT, mesgToShare );
List<ResolveInfo> activityList = getPackageManager().queryIntentActivities( shareIntent, 0 );
for ( final ResolveInfo app : activityList ) {
if ( (app.activityInfo.name).contains( packageName ) ) {
gotPackage = true;
final ActivityInfo activity = app.activityInfo;
ComponentName name = new ComponentName( activity.applicationInfo.packageName, activity.name );
shareIntent.addCategory( Intent.CATEGORY_LAUNCHER );
shareIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED );
shareIntent.setComponent( name );
startActivity( shareIntent );
break; // We already found what we were looking for. Don't need to execute the rest of the Loop
}
}
if ( !gotPackage )
Log.e("TAG", "Whatsapp is not installed in your device");
}

Yasir Tahir
- 790
- 1
- 11
- 31
0
if (isAppInstalled("com.whatsapp")) {
val sendIntent = Intent("android.intent.action.MAIN")
sendIntent.component = ComponentName("com.whatsapp", "com.whatsapp.Conversation")
sendIntent.putExtra(
"jid",
PhoneNumberUtils.stripSeparators("918219243720").toString() + "@s.whatsapp.net"
)
startActivity(sendIntent)
} else {
showToast("App is not currently installed on your phone")
}
Now Create fun()
private fun isAppInstalled(packageName: String): Boolean {
return try {
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
true
} catch (ignored: PackageManager.NameNotFoundException) {
false
}
}
Now Add same lines in Manifest file
<queries>
<package android:name="com.whatsapp" />
<package android:name="com.facebook.katana" />
</queries>

khemraj kashyap
- 19
- 3
-
Code-only answers are problematic. Please [edit] to explain what this code does, and what (if anything) it does better than the multiple previous answers from several years back. – tripleee Nov 22 '22 at 14:01