如果确定一个应用程序是否存在,如果不去玩店 [英] Identifying if an app exists, if not go to play store

查看:139
本文介绍了如果确定一个应用程序是否存在,如果不去玩店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有点了一个谎言的。

我想知道的是,是否有可能,如果一个设备上的犯规存在的应用程序,可以在进入游戏商店下载。我知道我需要把这个code。在

What I would like to know is that is it possible that if an app doesnt exist on a device, can it go into the play store to download it. I know I need to put this code in

Intent i = getPackageManager().getLaunchIntentForPackage("com.package.address");
    startActivity(i);

但如果那不存在的,我可以再赚去Play商店

But if that doesnt exist, can I then get it to go to the Play Store

推荐答案

您可以使用下面的函数之一检查应用程序是否安装或没有。

You can use one of the following function to check whether the app is installed or not.

功能1

private boolean isAppInstalled(String packageName) {
    PackageManager pm = getPackageManager();
    boolean installed = false;
    try {
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        installed = false;
    }
    return installed;
}

功能2

public boolean isAppInstalled(String targetPackage){
    List<ApplicationInfo> packages;
    PackageManager pm = getPackageManager();        
    packages = pm.getInstalledApplications(0);
    for (ApplicationInfo packageInfo : packages) {
        if(packageInfo.packageName.equals(targetPackage)) return true;
    }        
    return false;
}

用法

if(isAppInstalled("com.package.name")){
    //Your Code
}
else{
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.package.name")));
}

这篇关于如果确定一个应用程序是否存在,如果不去玩店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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