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:github.daneren2005.dsub.fragments.SubsonicFragment.java

protected void streamExternalPlayer(Entry entry, String format) {
    try {//from  w  ww.  j ava2 s. c om
        int maxBitrate = Util.getMaxVideoBitrate(context);

        Intent intent = new Intent(Intent.ACTION_VIEW);
        if ("hls".equals(format)) {
            intent.setDataAndType(Uri.parse(
                    MusicServiceFactory.getMusicService(context).getHlsUrl(entry.getId(), maxBitrate, context)),
                    "application/x-mpegURL");
        } else {
            intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(context)
                    .getVideoStreamUrl(format, maxBitrate, context, entry.getId())), "video/*");
        }
        intent.putExtra("title", entry.getTitle());

        List<ResolveInfo> intents = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (intents != null && intents.size() > 0) {
            startActivity(intent);
        } else {
            Util.toast(context, R.string.download_no_streaming_player);
        }
    } catch (Exception error) {
        String msg;
        if (error instanceof OfflineException || error instanceof ServerTooOldException) {
            msg = error.getMessage();
        } else {
            msg = context.getResources().getString(R.string.download_no_streaming_player) + " "
                    + error.getMessage();
        }

        Util.toast(context, msg, false);
    }
}

From source file:com.android.dialer.DialtactsFragment.java

private boolean canIntentBeHandled(Intent intent) {
    final PackageManager packageManager = getActivity().getPackageManager();
    final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return resolveInfo != null && resolveInfo.size() > 0;
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * Check whether an application exists that handles the pick activity.
 *
 * @return/* www .  j  a  va  2  s. co  m*/
 */
private boolean addLocationAlertPossible() {

    // Test whether intent exists for picking a location:
    PackageManager pm = getPackageManager();
    Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("geo:"));
    List<ResolveInfo> resolve_pick_location = pm.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    /*
     * for (int i = 0; i < resolve_pick_location.size(); i++) { Log.d(TAG,
     * "Activity name: " + resolve_pick_location.get(i).activityInfo.name);
     * }
     */

    // Check whether adding alerts is possible.
    intent = new Intent(Intent.ACTION_VIEW, Alert.Generic.CONTENT_URI);
    List<ResolveInfo> resolve_view_alerts = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

    boolean pick_location_possible = (resolve_pick_location.size() > 0);
    boolean view_alerts_possible = (resolve_view_alerts.size() > 0);
    if (debug) {
        Log.d(TAG, "Pick location possible: " + pick_location_possible);
    }
    if (debug) {
        Log.d(TAG, "View alerts possible: " + view_alerts_possible);
    }
    if (pick_location_possible && view_alerts_possible) {
        return true;
    }

    return false;
}

From source file:org.mozilla.gecko.BrowserApp.java

/**
 * Use a dummy Intent to do a default browser check.
 *
 * @return true if this package is the default browser on this device, false otherwise.
 *//* w ww  .  j av  a  2 s  . com*/
private boolean isDefaultBrowser(String action) {
    final Intent viewIntent = new Intent(action, Uri.parse("http://www.mozilla.org"));
    final ResolveInfo info = getPackageManager().resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
    if (info == null) {
        // No default is set
        return false;
    }

    final String packageName = info.activityInfo.packageName;
    return (TextUtils.equals(packageName, getPackageName()));
}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean isVCalendarAvailable(Context context) {
    final Intent intent = new Intent("android.intent.action.CALENDARCHOICE");
    intent.setType("text/x-vcalendar");
    final PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:com.android.mms.ui.MessageUtils.java

private static List<String> getHomes(Context context) {
    MmsLog.d(TAG, "DialogModeActivity.getHomes");

    List<String> names = new ArrayList<String>();
    PackageManager packageManager = context.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);

    for (ResolveInfo ri : resolveInfo) {
        names.add(ri.activityInfo.packageName);
        MmsLog.d(TAG, "package name=" + ri.activityInfo.packageName + " class name=" + ri.activityInfo.name);
    }/*from   w  w w.j  a va 2s  .  c o  m*/
    return names;
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

private static String getIntentResolveLabel(Intent intent, Context context) {
    final List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);

    // Pick first match, otherwise best found
    ResolveInfo bestResolve = null;/*from ww  w  . j  a v  a 2s  .c  o  m*/
    final int size = matches.size();
    if (size == 1) {
        bestResolve = matches.get(0);
    } else if (size > 1) {
        bestResolve = ResolveCache.getInstance(context).getBestResolve(intent, matches);
    }

    if (bestResolve == null) {
        return null;
    }

    return String.valueOf(bestResolve.loadLabel(context.getPackageManager()));
}

From source file:com.codename1.impl.android.AndroidImplementation.java

private Intent createIntentForURL(String url) {
    Intent intent;/*  ww  w . ja  v  a2  s  . c  om*/
    Uri uri;
    try {
        if (url.startsWith("intent")) {
            intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
        } else {
            if (url.startsWith("/") || url.startsWith("file:")) {
                if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        "This is required to open the file")) {
                    return null;
                }
            }
            intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            if (url.startsWith("/")) {
                File f = new File(url);
                Uri furi = null;
                try {
                    furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider",
                            f);
                } catch (Exception ex) {
                    f = makeTempCacheCopy(f);
                    furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider",
                            f);
                }

                if (Build.VERSION.SDK_INT < 21) {
                    List<ResolveInfo> resInfoList = getContext().getPackageManager()
                            .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
                    for (ResolveInfo resolveInfo : resInfoList) {
                        String packageName = resolveInfo.activityInfo.packageName;
                        getContext().grantUriPermission(packageName, furi,
                                Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    }
                }

                uri = furi;
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else {

                if (url.startsWith("file:")) {
                    File f = new File(removeFilePrefix(url));
                    System.out.println("File size: " + f.length());

                    Uri furi = null;
                    try {
                        furi = FileProvider.getUriForFile(getContext(),
                                getContext().getPackageName() + ".provider", f);
                    } catch (Exception ex) {
                        f = makeTempCacheCopy(f);
                        furi = FileProvider.getUriForFile(getContext(),
                                getContext().getPackageName() + ".provider", f);
                    }

                    if (Build.VERSION.SDK_INT < 21) {
                        List<ResolveInfo> resInfoList = getContext().getPackageManager()
                                .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
                        for (ResolveInfo resolveInfo : resInfoList) {
                            String packageName = resolveInfo.activityInfo.packageName;
                            getContext().grantUriPermission(packageName, furi,
                                    Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                                            | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        }
                    }
                    uri = furi;
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);

                } else {
                    uri = Uri.parse(url);
                }
            }
            String mimeType = getMimeType(url);
            if (mimeType != null) {
                intent.setDataAndType(uri, mimeType);
            } else {
                intent.setData(uri);
            }
        }

        return intent;
    } catch (Exception err) {
        com.codename1.io.Log.e(err);
        return null;
    }
}