Example usage for android.content.pm PackageManager MATCH_DEFAULT_ONLY

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

Introduction

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

Prototype

int MATCH_DEFAULT_ONLY

To view the source code for android.content.pm PackageManager MATCH_DEFAULT_ONLY.

Click Source Link

Document

Resolution and querying flag: if set, only filters that support the android.content.Intent#CATEGORY_DEFAULT will be considered for matching.

Usage

From source file:com.owncloud.android.ui.dialog.ShareLinkToDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mIntent = getArguments().getParcelable(ARG_INTENT);
    String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
    List<String> packagesToExcludeList = Arrays
            .asList(packagesToExclude != null ? packagesToExclude : new String[0]);
    mFile = getArguments().getParcelable(ARG_FILE_TO_SHARE);

    PackageManager pm = getActivity().getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY);
    Iterator<ResolveInfo> it = activities.iterator();
    ResolveInfo resolveInfo;/*from   ww  w.  j  a  v a2s . c o  m*/
    while (it.hasNext()) {
        resolveInfo = it.next();
        if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase())) {
            it.remove();
        }
    }

    boolean sendAction = mIntent.getBooleanExtra(Intent.ACTION_SEND, false);

    if (!sendAction) {
        // add activity for copy to clipboard
        Intent copyToClipboardIntent = new Intent(getActivity(), CopyToClipboardActivity.class);
        List<ResolveInfo> copyToClipboard = pm.queryIntentActivities(copyToClipboardIntent, 0);
        if (!copyToClipboard.isEmpty()) {
            activities.add(copyToClipboard.get(0));
        }
    }

    Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm));
    mAdapter = new ActivityAdapter(getActivity(), pm, activities);

    return createSelector(sendAction);

}

From source file:de.janrenz.app.mediathek.LiveFragment.java

public static boolean canDisplayM3u8(Context context) {
    if (context != null) {
        return false;
    }/* w w  w . ja  v  a 2  s.c  o m*/
    try {
        PackageManager packageManager = context.getPackageManager();
        Intent testIntent = new Intent(Intent.ACTION_VIEW);
        testIntent.setType("application/x-mpegURL");
        if (packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
            return true;
        }
    } catch (Exception e) {

    }
    return false;
}

From source file:io.github.hidroh.materialistic.AppUtils.java

public static void openWebUrlExternal(Context context, WebItem item, String url, CustomTabsSession session) {
    if (!hasConnection(context)) {
        context.startActivity(// ww w.j  a  v a 2s. co m
                new Intent(context, OfflineWebActivity.class).putExtra(OfflineWebActivity.EXTRA_URL, url));
        return;
    }
    Intent intent = createViewIntent(context, item, url, session);
    if (!HackerNewsClient.BASE_WEB_URL.contains(Uri.parse(url).getHost())) {
        if (intent.resolveActivity(context.getPackageManager()) != null) {
            context.startActivity(intent);
        }
        return;
    }
    List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    ArrayList<Intent> intents = new ArrayList<>();
    for (ResolveInfo info : activities) {
        if (info.activityInfo.packageName.equalsIgnoreCase(context.getPackageName())) {
            continue;
        }
        intents.add(createViewIntent(context, item, url, session).setPackage(info.activityInfo.packageName));
    }
    if (intents.isEmpty()) {
        return;
    }
    if (intents.size() == 1) {
        context.startActivity(intents.remove(0));
    } else {
        context.startActivity(Intent.createChooser(intents.remove(0), context.getString(R.string.chooser_title))
                .putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[intents.size()])));
    }
}

From source file:com.ruesga.rview.misc.ActivityHelper.java

@SuppressWarnings("Convert2streamapi")
public static void openUri(Context ctx, Uri uri, boolean excludeRview) {
    try {//  w w  w  .  java  2  s . c o  m
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true);
        intent.putExtra(Constants.EXTRA_SOURCE, ctx.getPackageName());

        if (excludeRview) {
            // Use a different url to find all the browsers activities
            Intent test = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.es"));
            PackageManager pm = ctx.getPackageManager();
            List<ResolveInfo> activities = pm.queryIntentActivities(test, PackageManager.MATCH_DEFAULT_ONLY);

            List<Intent> targetIntents = new ArrayList<>();
            for (ResolveInfo ri : activities) {
                if (!ri.activityInfo.packageName.equals(ctx.getPackageName())) {
                    Intent i = new Intent(Intent.ACTION_VIEW, uri);
                    i.setPackage(ri.activityInfo.packageName);
                    i.putExtra(Constants.EXTRA_SOURCE, ctx.getPackageName());
                    i.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true);
                    targetIntents.add(i);
                }
            }

            if (targetIntents.size() == 0) {
                throw new ActivityNotFoundException();
            } else if (targetIntents.size() == 1) {
                ctx.startActivity(targetIntents.get(0));
            } else {
                Intent chooserIntent = Intent.createChooser(intent, ctx.getString(R.string.action_open_with));
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                        targetIntents.toArray(new Parcelable[] {}));
                ctx.startActivity(chooserIntent);
            }
        } else {
            ctx.startActivity(intent);
        }

    } catch (ActivityNotFoundException ex) {
        // Fallback to default browser
        String msg = ctx.getString(R.string.exception_browser_not_found, uri.toString());
        Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.ultramegasoft.flavordex2.util.PhotoUtils.java

/**
 * Get an Intent to capture a photo.//from ww  w. j  a v a2  s.  com
 *
 * @return Image capture Intent
 */
@Nullable
public static Intent getTakePhotoIntent(@NonNull Context context) {
    try {
        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        final Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider",
                getOutputMediaFile());
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            intent.setClipData(ClipData.newUri(context.getContentResolver(), null, uri));
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else {
            final List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo activity : activities) {
                final String name = activity.activityInfo.packageName;
                context.grantUriPermission(name, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
        }

        return intent;
    } catch (IOException e) {
        Log.e(TAG, "Failed to create new file", e);
    }
    return null;
}

From source file:jahirfiquitiva.iconshowcase.utilities.utils.NotificationUtils.java

public static boolean isServiceAvailable(Context context, Class service) {
    if (context == null)
        return false;
    try {//from  www.  j  a  v  a2 s  .c o  m
        final PackageManager packageManager = context.getPackageManager();
        final Intent intent = new Intent(context, service);
        List resolveInfo = packageManager.queryIntentServices(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return resolveInfo.size() > 0;
    } catch (Exception ex) {
        return false;
    }
}

From source file:net.peterkuterna.android.apps.devoxxsched.util.ActivityHelper.java

/**
 * Takes a given intent and either starts a new activity to handle it (the
 * default behavior), or creates/updates a fragment (in the case of a
 * multi-pane activity) that can handle the intent.
 * /*from w w  w  . j  av  a 2 s.  com*/
 * Must be called from the main (UI) thread.
 */
public void openActivityOrFragment(Intent intent) {
    if (mActivity instanceof MultiPaneActivity) {
        MultiPaneActivity multiPaneActivity = (MultiPaneActivity) mActivity;
        final PackageManager pm = multiPaneActivity.getPackageManager();
        List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resolveInfoList) {
            final FragmentReplaceInfo fri = multiPaneActivity
                    .onSubstituteFragmentForActivityLaunch(resolveInfo.activityInfo.name);
            if (fri != null) {
                final Bundle arguments = intentToFragmentArguments(intent);
                final FragmentManager fm = multiPaneActivity.getSupportFragmentManager();

                try {
                    Fragment fragment = (Fragment) fri.getFragmentClass().newInstance();
                    fragment.setArguments(arguments);

                    FragmentTransaction ft = fm.beginTransaction();
                    ft.replace(fri.getContainerId(), fragment, fri.getFragmentTag());
                    multiPaneActivity.onBeforeCommitReplaceFragment(fm, ft, fragment);
                    ft.commit();
                    multiPaneActivity.onAfterCommitReplaceFragment(fm, ft, fragment);
                } catch (InstantiationException e) {
                    throw new IllegalStateException("Error creating new fragment.", e);
                } catch (IllegalAccessException e) {
                    throw new IllegalStateException("Error creating new fragment.", e);
                }
                return;
            }
        }
    }
    mActivity.startActivity(intent);

}

From source file:net.peterkuterna.android.apps.devoxxfrsched.util.ActivityHelper.java

/**
 * Takes a given intent and either starts a new activity to handle it (the
 * default behavior), or creates/updates a fragment (in the case of a
 * multi-pane activity) that can handle the intent.
 * /*  w ww  .  ja  v  a2  s  . c om*/
 * Must be called from the main (UI) thread.
 */
public void openActivityOrFragment(Intent intent) {
    if (mActivity instanceof BaseMultiPaneActivity) {
        BaseMultiPaneActivity multiPaneActivity = (BaseMultiPaneActivity) mActivity;
        final PackageManager pm = multiPaneActivity.getPackageManager();
        List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resolveInfoList) {
            final FragmentReplaceInfo fri = multiPaneActivity
                    .onSubstituteFragmentForActivityLaunch(resolveInfo.activityInfo.name);
            if (fri != null) {
                final Bundle arguments = intentToFragmentArguments(intent);
                final FragmentManager fm = multiPaneActivity.getSupportFragmentManager();

                try {
                    Fragment fragment = (Fragment) fri.getFragmentClass().newInstance();
                    fragment.setArguments(arguments);

                    FragmentTransaction ft = fm.beginTransaction();
                    ft.replace(fri.getContainerId(), fragment, fri.getFragmentTag());
                    multiPaneActivity.onBeforeCommitReplaceFragment(fm, ft, fragment);
                    ft.commit();
                    multiPaneActivity.onAfterCommitReplaceFragment(fm, ft, fragment);
                } catch (InstantiationException e) {
                    throw new IllegalStateException("Error creating new fragment.", e);
                } catch (IllegalAccessException e) {
                    throw new IllegalStateException("Error creating new fragment.", e);
                }
                return;
            }
        }
    }
    mActivity.startActivity(intent);
}

From source file:com.adguard.android.commons.BrowserUtils.java

public static boolean isSamsungBrowserAvailable(Context context) {
    Intent intent = new Intent();
    intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        for (ResolveInfo info : list) {
            if (info.activityInfo.packageName.contains(SAMSUNG_PACKAGE_PREFIX)
                    || info.activityInfo.packageName.contains(SAMSUNG)) {
                return true;
            }/*w w  w. j a v a  2 s.co m*/
        }
    }
    return false;
}

From source file:com.simplaapliko.apprater.AppRater.java

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