首页 > 移动平台 > 详细

android 判断应用程序是否已安装

时间:2016-07-14 09:52:38      阅读:334      评论:0      收藏:0      [点我收藏+]

1、判断是否安装
/*
* check the app is installed
*/
private boolean isAppInstalled(Context context,String packagename)
{
PackageInfo packageInfo;        
try {
            packageInfo = context.getPackageManager().getPackageInfo(packagename, 0);
         }catch (NameNotFoundException e) {
            packageInfo = null;
            e.printStackTrace();
         }
         if(packageInfo ==null){
            //System.out.println("没有安装");
            return false;
         }else{
            //System.out.println("已经安装");
            return true;
        }
}


2、判断后的逻辑: (转自:http://ruixiazun.blog.163.com/blog/static/906879182013021115923732/)
//已安装,打开程序,需传入参数包名:"com.skype.android.verizon" 
if(isAvilible(this, "com.skype.android.verizon")){ 
                Intent i = new Intent(); 
                ComponentName cn = new ComponentName("com.skype.android.verizon", 
                        "com.skype.android.verizon.SkypeActivity"); 
                i.setComponent(cn); 
                startActivityForResult(i, RESULT_OK);    
            } 
//未安装,跳转至market下载该程序 
else { 
                Uri uri = Uri.parse("market://details?id=com.skype.android.verizon");//id为包名 
                Intent it = new Intent(Intent.ACTION_VIEW, uri); 
                startActivity(it); 
            }

android 判断应用程序是否已安装

原文:http://www.cnblogs.com/Free-Thinker/p/5669286.html

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