##判断手机上是否存在应用,存在则打开

    package com.funs.openApp.utils;

    import java.util.List;
    
    import android.content.Context;
    import android.content.Intent;
    import android.content.pm.PackageInfo;
    import android.content.pm.PackageManager;
    
    public class PhoneAppUtil {
    
        private static PackageManager mPackageManager;
        private static Context mContext;
        
        /**给成员变量赋值*/
        private static void init(Context context){
            mContext = context;
            mPackageManager = mContext.getPackageManager();
        }
        /**
         * 判断包名所对应的应用在手机上是否存在
         * @param context        上下文
         * @param packageName    清单文件中注册的应用包名
         */
        public static boolean isAppExist(Context context,String packageName) {
            init(context);
            //得到已实例化的应用报名集合
            List<PackageInfo> packages = mPackageManager.getInstalledPackages(0);
            for (PackageInfo pi : packages) {
                //判断所查询的包名是否存在
                if (packageName.equalsIgnoreCase(pi.packageName)) {
                    return true;
                }
            }
            return false;
        }
        /**
         * 根据包名打开应用
         * @param context        上下文
         * @param packageName    将要打开的应用包名
         */
        public static void openApp(Context context,String packageName){
            init(context);
            Intent intent = mPackageManager.getLaunchIntentForPackage(packageName);
            context.startActivity(intent);
        }
    }