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

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); 
            }

posted @ 2016-07-14 09:45  brave-sailor  阅读(621)  评论(0编辑  收藏  举报