I want to check if multiple application is installed or not in user device and always get toast Application is not currently installed but whatsapp and instagram is installed. why?
String [] strings = new String [] {"com.whatsapp", "com.android.instagram" };
List<String> stringList = new ArrayList<String>(Arrays.asList(strings));
boolean isAppInstalled = appInstalledOrNot(String.valueOf(stringList));
if(isAppInstalled) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(String.valueOf(stringList));startActivity(LaunchIntent);
Toast.makeText(MainActivity.this,"Application is already installed.",Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this,"Application is not currently installed.",Toast.LENGTH_SHORT).show();
}
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}