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.docd.purefm.utils.PFMFileUtils.java

public static void openFileInExternalApp(@NonNull final Context context, @NonNull final File target) {
    final String mime = MimeTypes.getMimeType(target);
    if (mime != null) {
        final Intent i = new Intent(Intent.ACTION_VIEW);
        i.setDataAndType(Uri.fromFile(target), mime);
        final PackageManager packageManager = context.getPackageManager();
        if (packageManager == null) {
            throw new IllegalArgumentException("No PackageManager for context");
        }//  w w w.  j a  va  2 s .c  om
        if (packageManager.queryIntentActivities(i, 0).isEmpty()) {
            Toast.makeText(context, R.string.no_apps_to_open, Toast.LENGTH_SHORT).show();
            return;
        }
        try {
            context.startActivity(i);
        } catch (Exception e) {
            Toast.makeText(context, context.getString(R.string.could_not_open_file_) + e.getMessage(),
                    Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:de.madvertise.android.sdk.MadvertiseUtil.java

public static boolean checkForBrowserDeclaration(final Context context) {
    PackageManager pm = context.getPackageManager();
    Intent mainIntent = new Intent(context, MadvertiseActivity.class);
    List<ResolveInfo> returnList = pm.queryIntentActivities(mainIntent, 0);
    return returnList.size() > 0;
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java

private static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:com.readystatesoftware.notificationlog.Log.java

private static boolean isActivityAvailable(Context context, String className) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent();
    final String packageName = context.getApplicationInfo().packageName;
    intent.setClassName(packageName, className);
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:arun.com.chromer.browsing.customtabs.CustomTabs.java

/**
 * Returns all valid custom tab supporting browser packages on the system. Does not respect if
 * the package is default or not./*from w  w  w  . j  av a 2s  . c  o m*/
 *
 * @param context context to work with
 * @return list of packages supporting CCT
 */
@TargetApi(Build.VERSION_CODES.M)
@NonNull
public static List<String> getCustomTabSupportingPackages(Context context) {
    final PackageManager pm = context.getApplicationContext().getPackageManager();
    final Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    // Get all apps that can handle VIEW intents.
    final List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent,
            PackageManager.MATCH_ALL);
    final List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        if (isPackageSupportCustomTabs(context, info.activityInfo.packageName)) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }
    }
    return packagesSupportingCustomTabs;
}

From source file:com.felkertech.n.ActivityUtils.java

public static void browsePlugins(final Activity activity) {
    //Same opening
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }/*from   w  ww. j  ava  2 s . com*/
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);

    new MaterialDialog.Builder(activity).title(R.string.installed_plugins).items(plugin_names2)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog materialDialog, View view, int i,
                        CharSequence charSequence) {
                    // Load the given plugin with some additional info
                    ChannelDatabase cd = ChannelDatabase.getInstance(activity);
                    String s = cd.toString();
                    Intent intent = new Intent();
                    if (DEBUG) {
                        Log.d(TAG, "Try to start");
                    }
                    ResolveInfo plugin_info = plugins.get(i);
                    Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                            + plugin_info.activityInfo.name);

                    intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                            plugin_info.activityInfo.name);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EXTRA_READ_ALL);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ALL_CHANNELS, s);
                    activity.startActivity(intent);
                }
            }).positiveText(R.string.download_more_plugins)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse("http://play.google.com/store/search?q=cumulustv&c=apps"));
                    activity.startActivity(i);
                }
            }).show();
}

From source file:com.felkertech.n.ActivityUtils.java

public static void openPluginPicker(final boolean newChannel, final JsonChannel queriedChannel,
        final Activity activity) {
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<String>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }//w ww. j a v a  2  s  . c  om
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);
    if (DEBUG) {
        Log.d(TAG, "Load plugins " + plugin_names.toString());
    }
    if (plugin_names.size() == 1) {
        Intent intent = new Intent();
        if (newChannel) {
            if (DEBUG) {
                Log.d(TAG, "Try to start ");
            }
            ResolveInfo plugin_info = plugins.get(0);
            if (DEBUG) {
                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                        + plugin_info.activityInfo.name);
            }

            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
        } else {
            ResolveInfo plugin_info = plugins.get(0);
            Log.d(TAG,
                    plugin_info.activityInfo.applicationInfo.packageName + " " + plugin_info.activityInfo.name);
            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
        }
        activity.startActivity(intent);
    } else {
        new MaterialDialog.Builder(activity).items(plugin_names2).title(R.string.choose_an_app)
                .content(R.string.choose_default_app).itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog materialDialog, View view, int i,
                            CharSequence charSequence) {
                        Intent intent = new Intent();
                        if (newChannel) {
                            if (DEBUG) {
                                Log.d(TAG, "Try to start");
                            }
                            ResolveInfo plugin_info = plugins.get(i);
                            if (DEBUG) {
                                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                                        + plugin_info.activityInfo.name);
                            }

                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);

                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
                        } else {
                            ResolveInfo plugin_info = plugins.get(i);
                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
                        }
                        activity.startActivity(intent);
                    }
                }).show();
    }
}

From source file:com.linkbubble.MainApplication.java

public static void openAppStore(Context context, String url) {
    PackageManager manager = context.getPackageManager();
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));/*from w  ww  .  j  a v  a  2  s .c  o  m*/
    List<ResolveInfo> infos = manager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
    for (ResolveInfo info : infos) {
        IntentFilter filter = info.filter;
        if (filter != null && filter.hasAction(Intent.ACTION_VIEW)
                && filter.hasCategory(Intent.CATEGORY_BROWSABLE)) {
            if (info.activityInfo.packageName.equals(BuildConfig.STORE_PACKAGE)) {
                MainApplication.loadIntent(context, info.activityInfo.packageName, info.activityInfo.name, url,
                        -1, true);
                return;
            }
        }
    }
}

From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java

private static boolean isIntentAvailable(Context context, Intent intent) {
    PackageManager mgr = context.getPackageManager();
    List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:com.linkbubble.MainApplication.java

public static Intent getStoreIntent(Context context, String storeProUrl) {
    PackageManager manager = context.getPackageManager();
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(storeProUrl));
    List<ResolveInfo> infos = manager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
    for (ResolveInfo info : infos) {
        IntentFilter filter = info.filter;
        if (filter != null && filter.hasAction(Intent.ACTION_VIEW)
                && filter.hasCategory(Intent.CATEGORY_BROWSABLE)) {
            if (info.activityInfo.packageName.equals(BuildConfig.STORE_PACKAGE)) {
                Intent result = new Intent(Intent.ACTION_VIEW);
                result.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                result.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                        | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                result.setData(Uri.parse(storeProUrl));
                return result;
            }/*from ww w.j a  v a2 s . c  o  m*/
        }
    }

    return null;
}