本文整理汇总了Java中android.content.Intent.getPackage方法的典型用法代码示例。如果您正苦于以下问题:Java Intent.getPackage方法的具体用法?Java Intent.getPackage怎么用?Java Intent.getPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.getPackage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryIntentContentProviders
import android.content.Intent; //导入方法依赖的package包/类
@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();
}
}
示例2: verifyIntent
import android.content.Intent; //导入方法依赖的package包/类
/**
* 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());
}
}
示例3: shortcutExists
import android.content.Intent; //导入方法依赖的package包/类
/**
* 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;
}
示例4: queryIntentReceivers
import android.content.Intent; //导入方法依赖的package包/类
@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;
}
}
示例5: queryIntentServices
import android.content.Intent; //导入方法依赖的package包/类
@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;
}
}
示例6: queryIntentActivities
import android.content.Intent; //导入方法依赖的package包/类
@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();
}
}
示例7: queryIntentReceivers
import android.content.Intent; //导入方法依赖的package包/类
@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();
}
}
示例8: isSameIntent
import android.content.Intent; //导入方法依赖的package包/类
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;
}
示例9: handleUnsupportedLink
import android.content.Intent; //导入方法依赖的package包/类
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;
}
示例10: getIntentPackage
import android.content.Intent; //导入方法依赖的package包/类
private static String getIntentPackage(Intent intent) {
return intent.getComponent() == null
? intent.getPackage() : intent.getComponent().getPackageName();
}
示例11: getTargetPackage
import android.content.Intent; //导入方法依赖的package包/类
static String getTargetPackage(final Intent intent) {
final ComponentName component = intent.getComponent();
return component != null ? component.getPackageName() : intent.getPackage();
}
示例12: fromIntent
import android.content.Intent; //导入方法依赖的package包/类
public static ShortcutKey fromIntent(Intent intent, UserHandleCompat user) {
String shortcutId = intent.getStringExtra(
ShortcutInfoCompat.EXTRA_SHORTCUT_ID);
return new ShortcutKey(intent.getPackage(), user, shortcutId);
}
示例13: buildResolveList
import android.content.Intent; //导入方法依赖的package包/类
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");
}
}
}
示例14: startService
import android.content.Intent; //导入方法依赖的package包/类
@Override public ComponentName startService(final Intent service) {
return service.getComponent() != null ? service.getComponent() : new ComponentName(service.getPackage(), "A");
}
示例15: buildResolveList
import android.content.Intent; //导入方法依赖的package包/类
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");
}
}
}