Example usage for android.content.pm PackageManager queryIntentActivities

List of usage examples for android.content.pm PackageManager queryIntentActivities

Introduction

In this page you can find the example usage for android.content.pm PackageManager queryIntentActivities.

Prototype

public abstract List<ResolveInfo> queryIntentActivities(Intent intent, @ResolveInfoFlags int flags);

Source Link

Document

Retrieve all activities that can be performed for the given intent.

Usage

From source file:com.example.app_2.utils.Utils.java

public static boolean verifyResolves(Intent intent) {
    PackageManager packageManager = App_2.getAppContext().getPackageManager();
    List<ResolveInfo> activities = packageManager.queryIntentActivities(intent,
            PackageManager.PERMISSION_GRANTED);
    return activities.size() > 0;
}

From source file:com.teinproductions.tein.papyrosprogress.MainActivity.java

public static void openWebPage(MainActivity activity, String URL) {
    if (URLUtil.isValidUrl(URL)) {
        if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("use_custom_tabs", true)) {
            activity.tabsHelper.openURL(activity, URL);
        } else {//from  w w  w  . j  av a2s  . co m
            Uri webPage = Uri.parse(URL);
            Intent intent = new Intent(Intent.ACTION_VIEW, webPage);

            PackageManager packageManager = activity.getPackageManager();
            List activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

            if (activities.size() > 0) {
                activity.startActivity(intent);
            }
        }
    }
}

From source file:Main.java

public static void runApp(Context context, String paramString) {
    PackageManager localPackageManager = context.getPackageManager();
    try {/*w  w w  .java  2  s  .  co  m*/
        PackageInfo localPackageInfo = localPackageManager.getPackageInfo(paramString, 0);
        Intent localIntent1 = new Intent("android.intent.action.MAIN", null);
        localIntent1.setPackage(localPackageInfo.packageName);
        ResolveInfo localResolveInfo = (ResolveInfo) localPackageManager.queryIntentActivities(localIntent1, 0)
                .iterator().next();
        if (localResolveInfo != null) {
            String str1 = localResolveInfo.activityInfo.packageName;
            String str2 = localResolveInfo.activityInfo.name;
            Intent localIntent2 = new Intent("android.intent.action.MAIN");
            localIntent2.setComponent(new ComponentName(str1, str2));
            context.startActivity(localIntent2);
        }
    } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
        localNameNotFoundException.printStackTrace();
    }
}

From source file:com.ctrlplusz.dashclock.yr.configuration.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_yr_shortcut_default);
    }//from w ww.  j  av a2 s  . com

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_yr_shortcut_default);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:com.wareninja.android.opensource.oauth2login.common.Utils.java

public static boolean isIntentAvailable(final Context context, final Intent intent) {
    final PackageManager packageManager = context.getPackageManager();

    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:ca.mymenuapp.ui.activities.RestaurantActivity.java

/**
 * Check if any apps are installed on the app to receive this intent.
 *///from w w w . j a  va 2 s. c  o  m
public static boolean isAvailable(Context ctx, Intent intent) {
    final PackageManager mgr = ctx.getPackageManager();
    List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:com.eternizedlab.lunarcalendar.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default_title);
    }/*www .  j a v a 2 s.c  om*/

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default_title);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:com.appsimobile.appsihomeplugins.dashclock.configuration.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default);
    }//  w ww .j  a v a  2 s.c  om

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:com.google.android.apps.dashclock.configuration.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default);
    }/*from w  ww  .j  a  va2 s .  c o m*/

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.isEmpty()) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:com.dm.material.dashboard.candybar.helpers.RequestHelper.java

@NonNull
public static List<Request> loadMissingApps(@NonNull Context context) {
    List<Request> requests = new ArrayList<>();
    Database database = new Database(context);
    String activities = RequestHelper.loadAppFilter(context);
    PackageManager packageManager = context.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> installedApps = packageManager.queryIntentActivities(intent,
            PackageManager.GET_RESOLVED_FILTER);
    CandyBarMainActivity.sInstalledAppsCount = installedApps.size();

    try {//w w w  .j  ava2 s. c om
        Collections.sort(installedApps, new ResolveInfo.DisplayNameComparator(packageManager));
    } catch (Exception ignored) {
    }

    for (ResolveInfo app : installedApps) {
        String packageName = app.activityInfo.packageName;
        String activity = packageName + "/" + app.activityInfo.name;

        if (!activities.contains(activity)) {
            String name = LocaleHelper.getOtherAppLocaleName(context, new Locale("en-US"), packageName);
            if (name == null)
                name = app.activityInfo.loadLabel(packageManager).toString();

            boolean requested = database.isRequested(activity);
            requests.add(new Request(name, app.activityInfo.packageName, activity, requested));
        }
    }
    return requests;
}