package dolphin.android.util;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import java.util.List;

public class PackageUtils {
    /**
     * get package info
     *
     * @param context
     * @param cls
     * @return
     */
    public static PackageInfo getPackageInfo(Context context, Class<?> cls) {
        try {
            ComponentName comp = new ComponentName(context, cls);
            return context.getPackageManager().getPackageInfo(
                    comp.getPackageName(), 0);
            //return pinfo;
        } catch (PackageManager.NameNotFoundException e) {
            return null;
        }
    }

    /**
     * check if any activity can handle this intent
     *
     * @param context
     * @param intent
     * @return
     */
    public static boolean isCallable(Context context, Intent intent) {
        if (intent == null)
            return false;
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    }
}

@@ -824,16 +824,694 @@
 %0D%0A    %7D%0D
+%0A%09%0D%0A%09//http://goo.gl/xtf7I%0D%0A%09public static void enablePackage(Context context, Class%3C?%3E cls) %7B%0D%0A%09%09ComponentName activity = new ComponentName(context, cls);%0D%0A%09%09final PackageManager pm = context.getPackageManager();%0D%0A%0D%0A%09%09pm.setComponentEnabledSetting(activity,%0D%0A%09%09%09PackageManager.COMPONENT_ENABLED_STATE_ENABLED,%0D%0A%09%09%09PackageManager.DONT_KILL_APP);%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void disablePackage(Context context, Class%3C?%3E cls) %7B%0D%0A%09%09ComponentName activity = new ComponentName(context, cls);%0D%0A%09%09final PackageManager pm = context.getPackageManager();%0D%0A%0D%0A%09%09pm.setComponentEnabledSetting(activity,%0D%0A%09%09%09PackageManager.COMPONENT_ENABLED_STATE_DISABLED,%0D%0A%09%09%09PackageManager.DONT_KILL_APP);%0D%0A%09%7D%0D
 %0A%0D%0A    /

update PackageUtils.java