如何检查编程如果应用程序在Android的安装或没有? [英] How to check programmatically if an application is installed or not in Android?
本文介绍了如何检查编程如果应用程序在Android的安装或没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们已经通过编程安装的应用程序。
We have installed applications programmatically.
- 如果该应用程序已经安装在设备中的应用程序会自动打开。
- 否则安装特定的应用。
指导我。我不知道。 谢谢你。
Guide Me. I have no idea. Thanks.
推荐答案
试试这个:
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.Ch.Example.pack");
if(installed) {
//This intent will help you to launch if the package is already installed
Intent LaunchIntent = getPackageManager()
.getLaunchIntentForPackage("com.Ch.Example.pack");
startActivity(LaunchIntent);
System.out.println("App is already installed on your phone");
} else {
System.out.println("App 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;
}
}
这篇关于如何检查编程如果应用程序在Android的安装或没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文