Java Code Examples for android.content.Intent.getPackage()

The following are Jave code examples for showing how to use getPackage() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: TPlayer   File: VPackageManagerService.java   View Source Code Vote up 6 votes
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public List<ResolveInfo> queryIntentContentProviders(Intent intent, String resolvedType, int flags, int userId) {
    checkUserId(userId);
    flags = updateFlagsNought(flags);
    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, userId);
        }
        final VPackage pkg = mPackages.get(pkgName);
        if (pkg != null) {
            return mProviders.queryIntentForPackage(intent, resolvedType, flags, pkg.providers, userId);
        }
        return Collections.emptyList();
    }
}
 
Example 2
Project: SimpleUILauncher   File: GridSizeMigrationTask.java   View Source Code Vote up 6 votes
/**
 * Verifies if the intent should be restored.
 */
private void verifyIntent(String intentStr) throws Exception {
    Intent intent = Intent.parseUri(intentStr, 0);
    if (intent.getComponent() != null) {
        verifyPackage(intent.getComponent().getPackageName());
    } else if (intent.getPackage() != null) {
        // Only verify package if the component was null.
        verifyPackage(intent.getPackage());
    }
}
 
Example 3
Project: LaunchEnr   File: GridSizeMigrationTask.java   View Source Code Vote up 6 votes
/**
 * Verifies if the intent should be restored.
 */
private void verifyIntent(String intentStr) throws Exception {
    Intent intent = Intent.parseUri(intentStr, 0);
    if (intent.getComponent() != null) {
        verifyPackage(intent.getComponent().getPackageName());
    } else if (intent.getPackage() != null) {
        // Only verify package if the component was null.
        verifyPackage(intent.getPackage());
    }
}
 
Example 4
Project: LaunchEnr   File: AddWorkspaceItemsTask.java   View Source Code Vote up 6 votes
/**
 * Returns true if the shortcuts already exists on the workspace. This must be called after
 * the workspace has been loaded. We identify a shortcut by its intent.
 */
private boolean shortcutExists(BgDataModel dataModel, Intent intent, UserHandle user) {
    final String intentWithPkg, intentWithoutPkg;
    if (intent == null) {
        // Skip items with null intents
        return true;
    }
    if (intent.getComponent() != null) {
        // If component is not null, an intent with null package will produce
        // the same result and should also be a match.
        String packageName = intent.getComponent().getPackageName();
        if (intent.getPackage() != null) {
            intentWithPkg = intent.toUri(0);
            intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0);
        } else {
            intentWithPkg = new Intent(intent).setPackage(packageName).toUri(0);
            intentWithoutPkg = intent.toUri(0);
        }
    } else {
        intentWithPkg = intent.toUri(0);
        intentWithoutPkg = intent.toUri(0);
    }

    synchronized (dataModel) {
        for (ItemInfo item : dataModel.itemsIdMap) {
            if (item instanceof ShortcutInfo) {
                ShortcutInfo info = (ShortcutInfo) item;
                if (item.getIntent() != null && info.user.equals(user)) {
                    Intent copyIntent = new Intent(item.getIntent());
                    copyIntent.setSourceBounds(intent.getSourceBounds());
                    String s = copyIntent.toUri(0);
                    if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 5
Project: container   File: VPackageManagerService.java   View Source Code Vote up 6 votes
@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 6
Project: container   File: VPackageManagerService.java   View Source Code Vote up 6 votes
@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 7
Project: TPlayer   File: VPackageManagerService.java   View Source Code Vote up 6 votes
@Override
public List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) {
    checkUserId(userId);
    flags = updateFlagsNought(flags);
    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, userId);
        }
        final VPackage pkg = mPackages.get(pkgName);
        if (pkg != null) {
            return mActivities.queryIntentForPackage(intent, resolvedType, flags, pkg.activities, userId);
        }
        return Collections.emptyList();
    }
}
 
Example 8
Project: TPlayer   File: VPackageManagerService.java   View Source Code Vote up 6 votes
@Override
public List<ResolveInfo> queryIntentReceivers(Intent intent, String resolvedType, int flags, int userId) {
    checkUserId(userId);
    flags = updateFlagsNought(flags);
    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, userId);
        }
        final VPackage pkg = mPackages.get(pkgName);
        if (pkg != null) {
            return mReceivers.queryIntentForPackage(intent, resolvedType, flags, pkg.receivers, userId);
        }
        return Collections.emptyList();
    }
}
 
Example 9
Project: VirtualHook   File: ComponentUtils.java   View Source Code Vote up 6 votes
public static boolean isSameIntent(Intent a, Intent b) {
    if (a != null && b != null) {
        if (!ObjectsCompat.equals(a.getAction(), b.getAction())) {
            return false;
        }
        if (!ObjectsCompat.equals(a.getData(), b.getData())) {
            return false;
        }
        if (!ObjectsCompat.equals(a.getType(), b.getType())) {
            return false;
        }
        Object pkgA = a.getPackage();
        if (pkgA == null && a.getComponent() != null) {
            pkgA = a.getComponent().getPackageName();
        }
        String pkgB = b.getPackage();
        if (pkgB == null && b.getComponent() != null) {
            pkgB = b.getComponent().getPackageName();
        }
        if (!ObjectsCompat.equals(pkgA, pkgB)) {
            return false;
        }
        if (!ObjectsCompat.equals(a.getComponent(), b.getComponent())) {
            return false;
        }
        if (!ObjectsCompat.equals(a.getCategories(), b.getCategories())) {
            return false;
        }
    }
    return true;
}
 
Example 10
Project: VirtualHook   File: VPackageManagerService.java   View Source Code Vote up 6 votes
@Override
public List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) {
    checkUserId(userId);
    flags = updateFlagsNought(flags);
    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, userId);
        }
        final VPackage pkg = mPackages.get(pkgName);
        if (pkg != null) {
            return mActivities.queryIntentForPackage(intent, resolvedType, flags, pkg.activities, userId);
        }
        return Collections.emptyList();
    }
}
 
Example 11
Project: firefox-tv   File: IntentUtils.java   View Source Code Vote up 6 votes
private static boolean handleUnsupportedLink(final Context context, final IWebView webView, final Intent intent) {
    final String fallbackUrl = intent.getStringExtra(EXTRA_BROWSER_FALLBACK_URL);
    if (fallbackUrl != null) {
        webView.loadUrl(fallbackUrl);
        return true;
    }

    if (intent.getPackage() != null) {
        // The url included the target package:
        final String marketUri = MARKET_INTENT_URI_PACKAGE_PREFIX + intent.getPackage();
        final Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(marketUri));
        marketIntent.addCategory(Intent.CATEGORY_BROWSABLE);

        final PackageManager packageManager = context.getPackageManager();
        final ResolveInfo info = packageManager.resolveActivity(marketIntent, 0);
        final CharSequence marketTitle = info.loadLabel(packageManager);
        showConfirmationDialog(context, marketIntent,
                context.getString(R.string.external_app_prompt_no_app_title),
                R.string.external_app_prompt_no_app, marketTitle);

        // Stop loading, we essentially have a result.
        return true;
    }

    // If there's really no way to handle this, we just let the browser handle this URL
    // (which then shows the unsupported protocol page).
    return false;
}
 
Example 12
Project: TPlayer   File: ComponentUtils.java   View Source Code Vote up 6 votes
public static boolean isSameIntent(Intent a, Intent b) {
    if (a != null && b != null) {
        if (!ObjectsCompat.equals(a.getAction(), b.getAction())) {
            return false;
        }
        if (!ObjectsCompat.equals(a.getData(), b.getData())) {
            return false;
        }
        if (!ObjectsCompat.equals(a.getType(), b.getType())) {
            return false;
        }
        Object pkgA = a.getPackage();
        if (pkgA == null && a.getComponent() != null) {
            pkgA = a.getComponent().getPackageName();
        }
        String pkgB = b.getPackage();
        if (pkgB == null && b.getComponent() != null) {
            pkgB = b.getComponent().getPackageName();
        }
        if (!ObjectsCompat.equals(pkgA, pkgB)) {
            return false;
        }
        if (!ObjectsCompat.equals(a.getComponent(), b.getComponent())) {
            return false;
        }
        if (!ObjectsCompat.equals(a.getCategories(), b.getCategories())) {
            return false;
        }
    }
    return true;
}
 
Example 13
Project: LaunchEnr   File: InstallShortcutReceiver.java   View Source Code Vote up 5 votes
private static String getIntentPackage(Intent intent) {
    return intent.getComponent() == null
            ? intent.getPackage() : intent.getComponent().getPackageName();
}
 
Example 14
Project: MiPushFramework   File: CondomCore.java   View Source Code Vote up 5 votes
static String getTargetPackage(final Intent intent) {
	final ComponentName component = intent.getComponent();
	return component != null ? component.getPackageName() : intent.getPackage();
}
 
Example 15
Project: SimpleUILauncher   File: ShortcutKey.java   View Source Code Vote up 5 votes
public static ShortcutKey fromIntent(Intent intent, UserHandleCompat user) {
    String shortcutId = intent.getStringExtra(
            ShortcutInfoCompat.EXTRA_SHORTCUT_ID);
    return new ShortcutKey(intent.getPackage(), user, shortcutId);
}
 
Example 16
Project: container   File: IntentResolver.java   View Source Code Vote up 5 votes
private void buildResolveList(Intent intent, FastImmutableArraySet<String> categories, boolean debug,
		boolean defaultOnly, String resolvedType, String scheme, F[] src, List<R> dest) {
	final String action = intent.getAction();
	final Uri data = intent.getData();
	final String packageName = intent.getPackage();

	final int N = src != null ? src.length : 0;
	boolean hasNonDefaults = false;
	int i;
	F filter;
	for (i = 0; i < N && (filter = src[i]) != null; i++) {
		int match;

		// Is delivery being limited to filters owned by a particular
		// package?
		if (packageName != null && !isPackageForFilter(packageName, filter)) {
			continue;
		}
		// Do we already have this one?
		if (!allowFilterResult(filter, dest)) {
			continue;
		}

		match = filter.match(action, resolvedType, scheme, data, categories, TAG);
		if (match >= 0) {
			if (!defaultOnly || filter.hasCategory(Intent.CATEGORY_DEFAULT)) {
				final R oneResult = newResult(filter, match);
				if (oneResult != null) {
					dest.add(oneResult);
				}
			} else {
				hasNonDefaults = true;
			}
		}
	}

	if (hasNonDefaults) {
		if (dest.size() == 0) {
			VLog.w(TAG, "resolveIntent failed: found match, but none with CATEGORY_DEFAULT");
		} else if (dest.size() > 1) {
			VLog.w(TAG, "resolveIntent: multiple matches, only some with CATEGORY_DEFAULT");
		}
	}
}
 
Example 17
Project: condom   File: CondomMiscTest.java   View Source Code Vote up 5 votes
@Override public ComponentName startService(final Intent service) {
	return service.getComponent() != null ? service.getComponent() : new ComponentName(service.getPackage(), "A");
}
 
Example 18
Project: VirtualHook   File: IntentResolver.java   View Source Code Vote up 5 votes
private void buildResolveList(Intent intent, FastImmutableArraySet<String> categories,
							  boolean defaultOnly, String resolvedType, String scheme, F[] src, List<R> dest, int userId) {
	final String action = intent.getAction();
	final Uri data = intent.getData();
	final String packageName = intent.getPackage();

	final int N = src != null ? src.length : 0;
	boolean hasNonDefaults = false;
	int i;
	F filter;
	for (i = 0; i < N && (filter = src[i]) != null; i++) {
		int match;

		// Is delivery being limited to filters owned by a particular
		// package?
		if (packageName != null && !isPackageForFilter(packageName, filter)) {
			continue;
		}
		// Do we already have this one?
		if (!allowFilterResult(filter, dest)) {
			continue;
		}

		match = filter.filter.match(action, resolvedType, scheme, data, categories, TAG);
		if (match >= 0) {
			if (!defaultOnly || filter.filter.hasCategory(Intent.CATEGORY_DEFAULT)) {
				final R oneResult = newResult(filter, match, userId);
				if (oneResult != null) {
					dest.add(oneResult);
				}
			} else {
				hasNonDefaults = true;
			}
		}
	}

	if (hasNonDefaults) {
		if (dest.size() == 0) {
			VLog.w(TAG, "resolveIntent failed: found match, but none with CATEGORY_DEFAULT");
		} else if (dest.size() > 1) {
			VLog.w(TAG, "resolveIntent: multiple matches, only some with CATEGORY_DEFAULT");
		}
	}
}
 
Example 19
Project: FlickLauncher   File: ShortcutKey.java   View Source Code Vote up 5 votes
public static ShortcutKey fromIntent(Intent intent, UserHandleCompat user) {
    String shortcutId = intent.getStringExtra(
            ShortcutInfoCompat.EXTRA_SHORTCUT_ID);
    return new ShortcutKey(intent.getPackage(), user, shortcutId);
}
 
Example 20
Project: TPlayer   File: IntentResolver.java   View Source Code Vote up 5 votes
private void buildResolveList(Intent intent, FastImmutableArraySet<String> categories,
							  boolean defaultOnly, String resolvedType, String scheme, F[] src, List<R> dest, int userId) {
	final String action = intent.getAction();
	final Uri data = intent.getData();
	final String packageName = intent.getPackage();

	final int N = src != null ? src.length : 0;
	boolean hasNonDefaults = false;
	int i;
	F filter;
	for (i = 0; i < N && (filter = src[i]) != null; i++) {
		int match;

		// Is delivery being limited to filters owned by a particular
		// package?
		if (packageName != null && !isPackageForFilter(packageName, filter)) {
			continue;
		}
		// Do we already have this one?
		if (!allowFilterResult(filter, dest)) {
			continue;
		}

		match = filter.filter.match(action, resolvedType, scheme, data, categories, TAG);
		if (match >= 0) {
			if (!defaultOnly || filter.filter.hasCategory(Intent.CATEGORY_DEFAULT)) {
				final R oneResult = newResult(filter, match, userId);
				if (oneResult != null) {
					dest.add(oneResult);
				}
			} else {
				hasNonDefaults = true;
			}
		}
	}

	if (hasNonDefaults) {
		if (dest.size() == 0) {
			VLog.w(TAG, "resolveIntent failed: found match, but none with CATEGORY_DEFAULT");
		} else if (dest.size() > 1) {
			VLog.w(TAG, "resolveIntent: multiple matches, only some with CATEGORY_DEFAULT");
		}
	}
}