Question:
In the application, I need to enable the user to send messages through the messengers that are installed on his phone, how do I know if the user has Viber, WhatsApp and similar programs installed?
Answer:
private boolean isPackageInstalled(String packagename, Context context) {
PackageManager pm = context.getPackageManager();
try {
pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
In packagename
pass the name of the application package. For example, for Viber it is com.viber.voip