Java Code Examples for android.content.IntentFilter#countDataAuthorities()

The following examples show how to use android.content.IntentFilter#countDataAuthorities() . 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: CustomTabsHelper.java    From AndroidProjects with MIT License 7 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 2
Source File: CustomTabsHelper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 3
Source File: CustomTabsHelper.java    From droidddle with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 *
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 4
Source File: CustomTabsHelper.java    From MaterialHome with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 5
Source File: CustomTabsHelper.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 6
Source File: CustomTabsHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 7
Source File: CustomTabsHelper.java    From materialup with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 *
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 8
Source File: CustomTabsHelper.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 9
Source File: CustomTabsHelper.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 *
 * @param intent
 *         The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 10
Source File: CustomTabsHelper.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 11
Source File: CustomTabsHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 12
Source File: ChromeTabsDelegate.java    From SteamGifts with MIT License 6 votes vote down vote up
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0)
                continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 13
Source File: CustomTabsHelper.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 14
Source File: IntentUtils.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Search for intent handlers that are specific to this URL aka, specialized
 * apps like google maps or youtube
 */
private boolean isSpecializedHandlerAvailable(@NonNull Intent intent) {
    PackageManager pm = mActivity.getPackageManager();
    List<ResolveInfo> handlers = pm.queryIntentActivities(intent,
        PackageManager.GET_RESOLVED_FILTER);
    if (handlers == null || handlers.isEmpty()) {
        return false;
    }
    for (ResolveInfo resolveInfo : handlers) {
        IntentFilter filter = resolveInfo.filter;
        if (filter == null) {
            // No intent filter matches this intent?
            // Error on the side of staying in the browser, ignore
            continue;
        }
        // NOTICE: Use of && instead of || will cause the browser
        // to launch a new intent for every URL, using OR only
        // launches a new one if there is a non-browser app that
        // can handle it.
        // Previously we checked the number of data paths, but it is unnecessary
        // filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0
        if (filter.countDataAuthorities() == 0) {
            // Generic handler, skip
            continue;
        }
        return true;
    }
    return false;
}
 
Example 15
Source File: ExternalNavigationDelegateImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static ArrayList<String> getSpecializedHandlersWithFilter(
        List<ResolveInfo> infos, String filterPackageName) {
    ArrayList<String> result = new ArrayList<String>();
    if (infos == null) {
        return result;
    }

    int count = 0;
    for (ResolveInfo info : infos) {
        IntentFilter filter = info.filter;
        if (filter == null) {
            // Error on the side of classifying ResolveInfo as generic.
            continue;
        }
        if (filter.countDataAuthorities() == 0 && filter.countDataPaths() == 0) {
            // Don't count generic handlers.
            continue;
        }

        if (!TextUtils.isEmpty(filterPackageName)
                && (info.activityInfo == null
                           || !info.activityInfo.packageName.equals(filterPackageName))) {
            continue;
        }

        result.add(info.activityInfo != null ? info.activityInfo.packageName : "");
    }
    return result;
}
 
Example 16
Source File: IntentUtils.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Search for intent handlers that are specific to this URL aka, specialized
 * apps like google maps or youtube
 */
private boolean isSpecializedHandlerAvailable(Intent intent) {
	PackageManager pm = mActivity.getPackageManager();
	List<ResolveInfo> handlers = pm.queryIntentActivities(intent,
			PackageManager.GET_RESOLVED_FILTER);
	if (handlers == null || handlers.isEmpty()) {
		return false;
	}
	for (ResolveInfo resolveInfo : handlers) {
		IntentFilter filter = resolveInfo.filter;
		if (filter == null) {
			// No intent filter matches this intent?
			// Error on the side of staying in the browser, ignore
			continue;
		}
		// NOTICE: Use of && instead of || will cause the browser
		// to launch a new intent for every URL, using OR only
		// launches a new one if there is a non-browser app that
		// can handle it.
		if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) {
			// Generic handler, skip
			continue;
		}
		return true;
	}
	return false;
}
 
Example 17
Source File: IntentUtils.java    From JumpGo with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Search for intent handlers that are specific to this URL aka, specialized
 * apps like google maps or youtube
 */
private boolean isSpecializedHandlerAvailable(@NonNull Intent intent) {
    PackageManager pm = mActivity.getPackageManager();
    List<ResolveInfo> handlers = pm.queryIntentActivities(intent,
        PackageManager.GET_RESOLVED_FILTER);
    if (handlers == null || handlers.isEmpty()) {
        return false;
    }
    for (ResolveInfo resolveInfo : handlers) {
        IntentFilter filter = resolveInfo.filter;
        if (filter == null) {
            // No intent filter matches this intent?
            // Error on the side of staying in the browser, ignore
            continue;
        }
        // NOTICE: Use of && instead of || will cause the browser
        // to launch a new intent for every URL, using OR only
        // launches a new one if there is a non-browser app that
        // can handle it.
        // Previously we checked the number of data paths, but it is unnecessary
        // filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0
        if (filter.countDataAuthorities() == 0) {
            // Generic handler, skip
            continue;
        }
        return true;
    }
    return false;
}
 
Example 18
Source File: TabsHelper.java    From Ruisi with Apache License 2.0 5 votes vote down vote up
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) {
                continue;
            }
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) {
                continue;
            }
            if (resolveInfo.activityInfo == null) {
                continue;
            }
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
Example 19
Source File: IntentResolver.java    From container with GNU General Public License v3.0 4 votes vote down vote up
private boolean filterEquals(IntentFilter f1, IntentFilter f2) {
	int s1 = f1.countActions();
	int s2 = f2.countActions();
	if (s1 != s2) {
		return false;
	}
	for (int i = 0; i < s1; i++) {
		if (!f2.hasAction(f1.getAction(i))) {
			return false;
		}
	}
	s1 = f1.countCategories();
	s2 = f2.countCategories();
	if (s1 != s2) {
		return false;
	}
	for (int i = 0; i < s1; i++) {
		if (!f2.hasCategory(f1.getCategory(i))) {
			return false;
		}
	}
	s1 = f1.countDataTypes();
	s2 = f2.countDataTypes();
	if (s1 != s2) {
		return false;
	}
	s1 = f1.countDataSchemes();
	s2 = f2.countDataSchemes();
	if (s1 != s2) {
		return false;
	}
	for (int i = 0; i < s1; i++) {
		if (!f2.hasDataScheme(f1.getDataScheme(i))) {
			return false;
		}
	}
	s1 = f1.countDataAuthorities();
	s2 = f2.countDataAuthorities();
	if (s1 != s2) {
		return false;
	}
	s1 = f1.countDataPaths();
	s2 = f2.countDataPaths();
	if (s1 != s2) {
		return false;
	}
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		s1 = f1.countDataSchemeSpecificParts();
		s2 = f2.countDataSchemeSpecificParts();
		if (s1 != s2) {
			return false;
		}
	}
	return true;
}
 
Example 20
Source File: IntentResolver.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public static boolean filterEquals(IntentFilter f1, IntentFilter f2) {
    int s1 = f1.countActions();
    int s2 = f2.countActions();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasAction(f1.getAction(i))) {
            return false;
        }
    }
    s1 = f1.countCategories();
    s2 = f2.countCategories();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasCategory(f1.getCategory(i))) {
            return false;
        }
    }
    s1 = f1.countDataTypes();
    s2 = f2.countDataTypes();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasExactDataType(f1.getDataType(i))) {
            return false;
        }
    }
    s1 = f1.countDataSchemes();
    s2 = f2.countDataSchemes();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataScheme(f1.getDataScheme(i))) {
            return false;
        }
    }
    s1 = f1.countDataAuthorities();
    s2 = f2.countDataAuthorities();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataAuthority(f1.getDataAuthority(i))) {
            return false;
        }
    }
    s1 = f1.countDataPaths();
    s2 = f2.countDataPaths();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataPath(f1.getDataPath(i))) {
            return false;
        }
    }
    s1 = f1.countDataSchemeSpecificParts();
    s2 = f2.countDataSchemeSpecificParts();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataSchemeSpecificPart(f1.getDataSchemeSpecificPart(i))) {
            return false;
        }
    }
    return true;
}