Java Code Examples for android.content.pm.PackageManager#GET_RESOLVED_FILTER

The following examples show how to use android.content.pm.PackageManager#GET_RESOLVED_FILTER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VPackageManagerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected ResolveInfo newResult(PackageParser.ActivityIntentInfo info, int match) {
	final PackageParser.Activity activity = info.activity;
	ActivityInfo ai = PackageParserCompat.generateActivityInfo(activity, mFlags);
	if (ai == null) {
		return null;
	}
	final ResolveInfo res = new ResolveInfo();
	res.activityInfo = ai;
	if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
		res.filter = info;
	}
	res.priority = info.getPriority();
	res.preferredOrder = activity.owner.mPreferredOrder;
	// System.out.println("Result: " + res.activityInfo.className +
	// " = " + res.priority);
	res.match = match;
	res.isDefault = info.hasDefault;
	res.labelRes = info.labelRes;
	res.nonLocalizedLabel = info.nonLocalizedLabel;
	res.icon = info.icon;
	return res;
}
 
Example 2
Source File: VPackageManagerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected ResolveInfo newResult(PackageParser.ServiceIntentInfo filter, int match) {
	final PackageParser.Service service = filter.service;
	ServiceInfo si = PackageParserCompat.generateServiceInfo(service, mFlags);
	if (si == null) {
		return null;
	}
	final ResolveInfo res = new ResolveInfo();
	res.serviceInfo = si;
	if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
		res.filter = filter;
	}
	res.priority = filter.getPriority();
	res.preferredOrder = service.owner.mPreferredOrder;
	res.match = match;
	res.isDefault = filter.hasDefault;
	res.labelRes = filter.labelRes;
	res.nonLocalizedLabel = filter.nonLocalizedLabel;
	res.icon = filter.icon;
	return res;
}
 
Example 3
Source File: ProviderIntentResolver.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected ResolveInfo newResult(PackageParser.ProviderIntentInfo filter, int match) {
	final PackageParser.Provider provider = filter.provider;
	ProviderInfo pi = PackageParserCompat.generateProviderInfo(provider, mFlags);
	if (pi == null) {
		return null;
	}
	final ResolveInfo res = new ResolveInfo();
	res.providerInfo = pi;
	if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
		res.filter = filter;
	}
	res.priority = filter.getPriority();
	res.preferredOrder = provider.owner.mPreferredOrder;
	res.match = match;
	res.isDefault = filter.hasDefault;
	res.labelRes = filter.labelRes;
	res.nonLocalizedLabel = filter.nonLocalizedLabel;
	res.icon = filter.icon;
	return res;
}
 
Example 4
Source File: BrowserSelector.java    From AppAuth-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves the full list of browsers installed on the device. Two entries will exist
 * for each browser that supports custom tabs, with the {@link BrowserDescriptor#useCustomTab}
 * flag set to `true` in one and `false` in the other. The list is in the
 * order returned by the package manager, so indirectly reflects the user's preferences
 * (i.e. their default browser, if set, should be the first entry in the list).
 */
@SuppressLint("PackageManagerGetSignatures")
@NonNull
public static List<BrowserDescriptor> getAllBrowsers(Context context) {
    PackageManager pm = context.getPackageManager();
    List<BrowserDescriptor> browsers = new ArrayList<>();
    String defaultBrowserPackage = null;

    int queryFlag = PackageManager.GET_RESOLVED_FILTER;
    if (VERSION.SDK_INT >= VERSION_CODES.M) {
        queryFlag |= PackageManager.MATCH_ALL;
    }
    // When requesting all matching activities for an intent from the package manager,
    // the user's preferred browser is not guaranteed to be at the head of this list.
    // Therefore, the preferred browser must be separately determined and the resultant
    // list of browsers reordered to restored this desired property.
    ResolveInfo resolvedDefaultActivity =
            pm.resolveActivity(BROWSER_INTENT, 0);
    if (resolvedDefaultActivity != null) {
        defaultBrowserPackage = resolvedDefaultActivity.activityInfo.packageName;
    }
    List<ResolveInfo> resolvedActivityList =
            pm.queryIntentActivities(BROWSER_INTENT, queryFlag);

    for (ResolveInfo info : resolvedActivityList) {
        // ignore handlers which are not browsers
        if (!isFullBrowser(info)) {
            continue;
        }

        try {
            int defaultBrowserIndex = 0;
            PackageInfo packageInfo = pm.getPackageInfo(
                    info.activityInfo.packageName,
                    PackageManager.GET_SIGNATURES);

            if (hasWarmupService(pm, info.activityInfo.packageName)) {
                BrowserDescriptor customTabBrowserDescriptor =
                        new BrowserDescriptor(packageInfo, true);
                if (info.activityInfo.packageName.equals(defaultBrowserPackage)) {
                    // If the default browser is having a WarmupService,
                    // will it be added to the beginning of the list.
                    browsers.add(defaultBrowserIndex, customTabBrowserDescriptor);
                    defaultBrowserIndex++;
                } else {
                    browsers.add(customTabBrowserDescriptor);
                }
            }

            BrowserDescriptor fullBrowserDescriptor =
                    new BrowserDescriptor(packageInfo, false);
            if (info.activityInfo.packageName.equals(defaultBrowserPackage)) {
                // The default browser is added to the beginning of the list.
                // If there is support for Custom Tabs, will the one disabling Custom Tabs
                // be added as the second entry.
                browsers.add(defaultBrowserIndex, fullBrowserDescriptor);
            } else {
                browsers.add(fullBrowserDescriptor);
            }
        } catch (NameNotFoundException e) {
            // a descriptor cannot be generated without the package info
        }
    }

    return browsers;
}