如果安装或重新定向到谷歌播放启动应用程序 [英] Launching an application if installed or redirect to Google Play

查看:106
本文介绍了如果安装或重新定向到谷歌播放启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到现在为止,我用这个code。如果安装到启动第三方应用程序或重定向到谷歌Play下载,如果尚未安装:

Until now I was using this code to launch a 3rd party application if installed or redirect to Google Play to download it if not installed already:

Intent intent = Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (intent != null)
{
/* we found the activity now start the activity */
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else
{
/* bring user to the market or let them choose an app? */
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id="+"com.package.address"));
startActivity(intent);
}

在这里读书,我发现启动,而不是特定活动(这是我想要的结果)的方式:

Reading here I found the way to launch a particular activity instead (that was my desired result):

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new  ComponentName("com.package.address","com.package.address.xxxxxActivity"));
startActivity(intent);

它的工作开展特定活动,但我非常非常非常有限的知识,我不知道如何修改条件以启动链接到谷歌播放,如果没有安装的应用程序。

It works launching the particular activity, but with my very very very limited knowledge I don't know how to modify the condition to launch the link to Google Play if the app isn't installed.

希望有人能帮助我^^
谢谢!

Hope someone can help me^^ Thanks!

推荐答案

您可以使用一个尝试捕捉,看看包名存在

you can use a try catch to see if the package name exists

try {
    PackageManager pm=getPackageManager();
    PackageInfo info=pm.getPackageInfo("com.package.address",PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
    //launch play store
}

这篇关于如果安装或重新定向到谷歌播放启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆