首页 > 移动平台 > 详细

Android 判断app是否安装

时间:2017-10-25 10:29:58      阅读:259      评论:0      收藏:0      [点我收藏+]

1.

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

2.

public boolean isAppInstalled(Context context, String packageName) {  
        final PackageManager packageManager = context.getPackageManager();  
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);  
        List<String> pName = new ArrayList<String>();  
        if (pinfo != null) {  
            for (int i = 0; i < pinfo.size(); i++) {  
                String pn = pinfo.get(i).packageName;  
                pName.add(pn);  
            }  
        }  
        return pName.contains(packageName);  
    }  

例子: 

                 if (isInstallApp(MainActivity.this, "com.xxx")) {  
                    System.out.println("Installed!!");  
                } else {  
                    System.out.println("Not installed!!");  
                }      

 

Android 判断app是否安装

原文:http://www.cnblogs.com/zhujiabin/p/7727184.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!