检测编程应用程序是否安装在Android [英] Detecting programmatically whether an app is installed on Android
问题描述
我已经注册的URL方案为我的Android应用(假设的myapp://主机)。
I have registered a url scheme for my Android app (let's say myapp://host).
在我的其他应用程序,我可以通过使用意图启动该应用程序,但我要如何检查是否安装了第一个应用程序,而无需启动呢?
On my other app, I can launch that app by using Intent, but how do I check whether the first app is installed without launching it?
在iOS上,它是那么容易,因为
in iOS, it is as easy as
[[UIApplication sharedApplication] canOpenUrl:@"myapp://"];
有Android中的等价? (简单的方法)
is there an equivalent in Android? (easy way)
我想使用URL方案进行检查。我知道如何使用包名去检查,但我不知道如何从PackageInfo获得url方案,以及...(更难方式)
I'd like to check using url scheme. I know how to check using package name, but I do not know how to get the url scheme from PackageInfo as well... (harder way)
PackageManager pm = m_cContext.getPackageManager();
boolean installed = false;
try {
@SuppressWarnings("unused")
PackageInfo pInfo = pm.getPackageInfo(szPackageName, PackageManager.GET_ACTIVITIES);
installed = true;
}
catch (PackageManager.NameNotFoundException e) {
installed = false;
}
在此先感谢!
请注意:这是iOS的同一个问题的Android版本:
<一href=\"http://stackoverflow.com/questions/3808691/detecting-programmatically-whether-an-app-is-installed-on-iphone/3808757#comment16408047_3808757\">Detecting一个应用程序编程是否安装在iPhone上
Note: This is the Android version of the same question for iOS: Detecting programmatically whether an app is installed on iPhone
推荐答案
如果你知道如何启动应用程序,然后创建启动您的应用的意图,然后调用queryIntentActivities
If you know how to launch the app, then create the intent that launches your app and then call queryIntentActivities
Intent intent = //your app launching intent goes here
PackageManager packageManager = mContext.getPackageManager();
List<ResolveInfo> resolvedActivities = packageManager.queryIntentActivities(intent,0);
if(resolvedActivities.size() >0)
\\present
这篇关于检测编程应用程序是否安装在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!