Java Code Examples for android.content.Intent#getSelector()

The following examples show how to use android.content.Intent#getSelector() . These examples are extracted from open source projects. 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 Project: 365browser   File: WebApkValidator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Fetches the list of resolve infos from the PackageManager that can handle the URL.
 *
 * @param context The application context.
 * @param url The url to check.
 * @return The list of resolve infos found that can handle the URL.
 */
private static List<ResolveInfo> resolveInfosForUrl(Context context, String url) {
    Intent intent;
    try {
        intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
    } catch (Exception e) {
        return new LinkedList<>();
    }

    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.setComponent(null);
    Intent selector = intent.getSelector();
    if (selector != null) {
        selector.addCategory(Intent.CATEGORY_BROWSABLE);
        selector.setComponent(null);
    }
    return context.getPackageManager().queryIntentActivities(
            intent, PackageManager.GET_RESOLVED_FILTER);
}
 
Example 2
Source Project: VirtualAPK   File: LoadedPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<ResolveInfo> queryIntentActivities(Intent intent, int flags) {
    ComponentName component = intent.getComponent();
    if (null == component) {
        if (intent.getSelector() != null) {
            intent = intent.getSelector();
            component = intent.getComponent();
        }
    }

    if (null != component) {
        LoadedPlugin plugin = mPluginManager.getLoadedPlugin(component);
        if (null != plugin) {
            ActivityInfo activityInfo = plugin.getActivityInfo(component);
            if (activityInfo != null) {
                ResolveInfo resolveInfo = new ResolveInfo();
                resolveInfo.activityInfo = activityInfo;
                return Arrays.asList(resolveInfo);
            }
        }
    }

    List<ResolveInfo> all = new ArrayList<ResolveInfo>();

    List<ResolveInfo> pluginResolveInfos = mPluginManager.queryIntentActivities(intent, flags);
    if (null != pluginResolveInfos && pluginResolveInfos.size() > 0) {
        all.addAll(pluginResolveInfos);
    }

    List<ResolveInfo> hostResolveInfos = this.mHostPackageManager.queryIntentActivities(intent, flags);
    if (null != hostResolveInfos && hostResolveInfos.size() > 0) {
        all.addAll(hostResolveInfos);
    }

    return all;
}
 
Example 3
Source Project: VirtualAPK   File: LoadedPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
    ComponentName component = intent.getComponent();
    if (null == component) {
        if (intent.getSelector() != null) {
            intent = intent.getSelector();
            component = intent.getComponent();
        }
    }

    if (null != component) {
        LoadedPlugin plugin = mPluginManager.getLoadedPlugin(component);
        if (null != plugin) {
            ActivityInfo activityInfo = plugin.getReceiverInfo(component);
            if (activityInfo != null) {
                ResolveInfo resolveInfo = new ResolveInfo();
                resolveInfo.activityInfo = activityInfo;
                return Arrays.asList(resolveInfo);
            }
        }
    }

    List<ResolveInfo> all = new ArrayList<>();

    List<ResolveInfo> pluginResolveInfos = mPluginManager.queryBroadcastReceivers(intent, flags);
    if (null != pluginResolveInfos && pluginResolveInfos.size() > 0) {
        all.addAll(pluginResolveInfos);
    }

    List<ResolveInfo> hostResolveInfos = this.mHostPackageManager.queryBroadcastReceivers(intent, flags);
    if (null != hostResolveInfos && hostResolveInfos.size() > 0) {
        all.addAll(hostResolveInfos);
    }

    return all;
}
 
Example 4
Source Project: VirtualAPK   File: LoadedPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
    ComponentName component = intent.getComponent();
    if (null == component) {
        if (intent.getSelector() != null) {
            intent = intent.getSelector();
            component = intent.getComponent();
        }
    }

    if (null != component) {
        LoadedPlugin plugin = mPluginManager.getLoadedPlugin(component);
        if (null != plugin) {
            ServiceInfo serviceInfo = plugin.getServiceInfo(component);
            if (serviceInfo != null) {
                ResolveInfo resolveInfo = new ResolveInfo();
                resolveInfo.serviceInfo = serviceInfo;
                return Arrays.asList(resolveInfo);
            }
        }
    }

    List<ResolveInfo> all = new ArrayList<ResolveInfo>();

    List<ResolveInfo> pluginResolveInfos = mPluginManager.queryIntentServices(intent, flags);
    if (null != pluginResolveInfos && pluginResolveInfos.size() > 0) {
        all.addAll(pluginResolveInfos);
    }

    List<ResolveInfo> hostResolveInfos = this.mHostPackageManager.queryIntentServices(intent, flags);
    if (null != hostResolveInfos && hostResolveInfos.size() > 0) {
        all.addAll(hostResolveInfos);
    }

    return all;
}
 
Example 5
@Override
public List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) {
	checkUserId(userId);
	ComponentName comp = intent.getComponent();
	if (comp == null) {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
			if (intent.getSelector() != null) {
				intent = intent.getSelector();
				comp = intent.getComponent();
			}
		}
	}
	if (comp != null) {
		final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
		final ActivityInfo ai = getActivityInfo(comp, flags, userId);
		if (ai != null) {
			final ResolveInfo ri = new ResolveInfo();
			ri.activityInfo = ai;
			list.add(ri);
		}
		return list;
	}

	// reader
	synchronized (mPackages) {
		final String pkgName = intent.getPackage();
		if (pkgName == null) {
			return mActivities.queryIntent(intent, resolvedType, flags);
		}
		final PackageParser.Package pkg = mPackages.get(pkgName);
		if (pkg != null) {
			return mActivities.queryIntentForPackage(intent, resolvedType, flags, pkg.activities);
		}
		return new ArrayList<ResolveInfo>();
	}
}
 
Example 6
@Override
public List<ResolveInfo> queryIntentReceivers(Intent intent, String resolvedType, int flags, int userId) {
	ComponentName comp = intent.getComponent();
	if (comp == null) {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
			if (intent.getSelector() != null) {
				intent = intent.getSelector();
				comp = intent.getComponent();
			}
		}
	}
	if (comp != null) {
		List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
		ActivityInfo ai = getReceiverInfo(comp, flags, userId);
		if (ai != null) {
			ResolveInfo ri = new ResolveInfo();
			ri.activityInfo = ai;
			list.add(ri);
		}
		return list;
	}

	// reader
	synchronized (mPackages) {
		String pkgName = intent.getPackage();
		if (pkgName == null) {
			return mReceivers.queryIntent(intent, resolvedType, flags);
		}
		final PackageParser.Package pkg = mPackages.get(pkgName);
		if (pkg != null) {
			return mReceivers.queryIntentForPackage(intent, resolvedType, flags, pkg.receivers);
		}
		return null;
	}
}
 
Example 7
@Override
public List<ResolveInfo> queryIntentServices(Intent intent, String resolvedType, int flags, int userId) {
	checkUserId(userId);
	ComponentName comp = intent.getComponent();
	if (comp == null) {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
			if (intent.getSelector() != null) {
				intent = intent.getSelector();
				comp = intent.getComponent();
			}
		}
	}
	if (comp != null) {
		final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
		final ServiceInfo si = getServiceInfo(comp, flags, userId);
		if (si != null) {
			final ResolveInfo ri = new ResolveInfo();
			ri.serviceInfo = si;
			list.add(ri);
		}
		return list;
	}

	// reader
	synchronized (mPackages) {
		String pkgName = intent.getPackage();
		if (pkgName == null) {
			return mServices.queryIntent(intent, resolvedType, flags);
		}
		final PackageParser.Package pkg = mPackages.get(pkgName);
		if (pkg != null) {
			return mServices.queryIntentForPackage(intent, resolvedType, flags, pkg.services);
		}
		return null;
	}
}
 
Example 8
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public List<ResolveInfo> queryIntentContentProviders(Intent intent, String resolvedType, int flags, int userId) {
	checkUserId(userId);
	ComponentName comp = intent.getComponent();
	if (comp == null) {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
			if (intent.getSelector() != null) {
				intent = intent.getSelector();
				comp = intent.getComponent();
			}
		}
	}
	if (comp != null) {
		final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
		final ProviderInfo pi = getProviderInfo(comp, flags, userId);
		if (pi != null) {
			final ResolveInfo ri = new ResolveInfo();
			ri.providerInfo = pi;
			list.add(ri);
		}
		return list;
	}
	// reader
	synchronized (mPackages) {
		String pkgName = intent.getPackage();
		if (pkgName == null) {
			return mProviders.queryIntent(intent, resolvedType, flags);
		}
		final PackageParser.Package pkg = mPackages.get(pkgName);
		if (pkg != null) {
			return mProviders.queryIntentForPackage(intent, resolvedType, flags, pkg.providers);
		}
		return null;
	}
}
 
Example 9
private boolean handleIncomingIntentInternal(
        Context context, Intent intent, boolean isCustomTabsIntent, long startTime) {
    boolean isEnabled = isEnabled(context);
    if (!isEnabled || (isCustomTabsIntent && !IntentUtils.safeGetBooleanExtra(
            intent, CUSTOM_APPS_INSTANT_APP_EXTRA, false))) {
        Log.i(TAG, "Not handling with Instant Apps. Enabled? " + isEnabled);
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(intent, DO_NOT_LAUNCH_EXTRA, false)) {
        maybeRecordFallbackStats(intent);
        Log.i(TAG, "Not handling with Instant Apps (DO_NOT_LAUNCH_EXTRA)");
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(
            intent, IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false)
            || IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)
            || isIntentFromChrome(context, intent)
            || (IntentHandler.getUrlFromIntent(intent) == null)) {
        Log.i(TAG, "Not handling with Instant Apps (other)");
        return false;
    }

    // Used to search for the intent handlers. Needs null component to return correct results.
    Intent intentCopy = new Intent(intent);
    intentCopy.setComponent(null);
    Intent selector = intentCopy.getSelector();
    if (selector != null) selector.setComponent(null);

    if (!(isCustomTabsIntent || isChromeDefaultHandler(context))
            || ExternalNavigationDelegateImpl.isPackageSpecializedHandler(
                    context, null, intentCopy)) {
        // Chrome is not the default browser or a specialized handler exists.
        Log.i(TAG, "Not handling with Instant Apps because Chrome is not default or "
                + "there's a specialized handler");
        return false;
    }

    Intent callbackIntent = new Intent(intent);
    callbackIntent.putExtra(DO_NOT_LAUNCH_EXTRA, true);
    callbackIntent.putExtra(INSTANT_APP_START_TIME_EXTRA, startTime);

    return tryLaunchingInstantApp(context, intent, isCustomTabsIntent, callbackIntent);
}
 
Example 10
Source Project: 365browser   File: InstantAppsHandler.java    License: Apache License 2.0 4 votes vote down vote up
private boolean handleIncomingIntentInternal(
        Context context, Intent intent, boolean isCustomTabsIntent, long startTime,
        boolean isRedirect) {
    if (!isRedirect && !isCustomTabsIntent && BuildInfo.isAtLeastO()) {
        Log.i(TAG, "Disabled for Android O+");
        return false;
    }

    if (isCustomTabsIntent && !IntentUtils.safeGetBooleanExtra(
            intent, CUSTOM_APPS_INSTANT_APP_EXTRA, false)) {
        Log.i(TAG, "Not handling with Instant Apps (missing CUSTOM_APPS_INSTANT_APP_EXTRA)");
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(intent, DO_NOT_LAUNCH_EXTRA, false)
            || (BuildInfo.isAtLeastO() && (intent.getFlags() & FLAG_DO_NOT_LAUNCH) != 0)) {
        maybeRecordFallbackStats(intent);
        Log.i(TAG, "Not handling with Instant Apps (DO_NOT_LAUNCH_EXTRA)");
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(
            intent, IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false)
            || IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)
            || isIntentFromChrome(context, intent)
            || (IntentHandler.getUrlFromIntent(intent) == null)) {
        Log.i(TAG, "Not handling with Instant Apps (other)");
        return false;
    }

    // Used to search for the intent handlers. Needs null component to return correct results.
    Intent intentCopy = new Intent(intent);
    intentCopy.setComponent(null);
    Intent selector = intentCopy.getSelector();
    if (selector != null) selector.setComponent(null);

    if (!(isCustomTabsIntent || isChromeDefaultHandler(context))
            || ExternalNavigationDelegateImpl.isPackageSpecializedHandler(null, intentCopy)) {
        // Chrome is not the default browser or a specialized handler exists.
        Log.i(TAG, "Not handling with Instant Apps because Chrome is not default or "
                + "there's a specialized handler");
        return false;
    }

    Intent callbackIntent = new Intent(intent);
    callbackIntent.putExtra(DO_NOT_LAUNCH_EXTRA, true);
    callbackIntent.putExtra(INSTANT_APP_START_TIME_EXTRA, startTime);

    return tryLaunchingInstantApp(context, intent, isCustomTabsIntent, callbackIntent);
}