如何检查Android设备中安装了Whatsapp? [英] How to check Whatsapp is installed in device in android?
本文介绍了如何检查Android设备中安装了Whatsapp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查whatsapp是否已安装在移动设备中(如果已安装),则显示已安装",如果未安装,则显示未安装",请提供帮助.
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.
推荐答案
您可以使用此代码.它将检查软件包是否已安装.
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...
boolean installed = appInstalledOrNot("com.whatsapp");
if(installed) {
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) {
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
}
这篇关于如何检查Android设备中安装了Whatsapp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文