本文整理了Java中android.content.Intent.getPackage()
方法的一些代码示例,展示了Intent.getPackage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.getPackage()
方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:getPackage
暂无
代码示例来源:origin: ACRA/acra
/**
* Finds the package name of the default email client supporting attachments
*
* @param resolveActivity the resolved activity
* @param initialIntents a list of intents to be used when
* @return package name of the default email client, or null if more than one app match
*/
@Nullable
private String getPackageName(@NonNull ComponentName resolveActivity, @NonNull List<Intent> initialIntents) {
String packageName = resolveActivity.getPackageName();
if (packageName.equals("android")) {
//multiple activities support the intent and no default is set
if (initialIntents.size() > 1) {
packageName = null;
} else if (initialIntents.size() == 1) {
//only one of them supports attachments, use that one
packageName = initialIntents.get(0).getPackage();
}
}
return packageName;
}
代码示例来源:origin: square/assertj-android
public IntentAssert hasPackage(String packageName) {
isNotNull();
String actualPackage = actual.getPackage();
assertThat(packageName)
.overridingErrorMessage("Expected package <%s> but was <%s>.", packageName, actualPackage)
.isEqualTo(actualPackage);
return this;
}
代码示例来源:origin: android-hacker/VirtualXposed
public static Intent redirectBroadcastIntent(Intent intent, int userId) {
Intent newIntent = intent.cloneFilter();
newIntent.setComponent(null);
newIntent.setPackage(null);
ComponentName component = intent.getComponent();
String pkg = intent.getPackage();
if (component != null) {
newIntent.putExtra("_VA_|_user_id_", userId);
newIntent.setAction(String.format("_VA_%s_%s", component.getPackageName(), component.getClassName()));
newIntent.putExtra("_VA_|_component_", component);
newIntent.putExtra("_VA_|_intent_", new Intent(intent));
} else if (pkg != null) {
newIntent.putExtra("_VA_|_user_id_", userId);
newIntent.putExtra("_VA_|_creator_", pkg);
newIntent.putExtra("_VA_|_intent_", new Intent(intent));
String protectedAction = SpecialComponentList.protectAction(intent.getAction());
if (protectedAction != null) {
newIntent.setAction(protectedAction);
}
} else {
newIntent.putExtra("_VA_|_user_id_", userId);
newIntent.putExtra("_VA_|_intent_", new Intent(intent));
String protectedAction = SpecialComponentList.protectAction(intent.getAction());
if (protectedAction != null) {
newIntent.setAction(protectedAction);
}
}
return newIntent;
}
代码示例来源:origin: oasisfeng/condom
static String getTargetPackage(final Intent intent) {
final ComponentName component = intent.getComponent();
return component != null ? component.getPackageName() : intent.getPackage();
}
代码示例来源:origin: robolectric/robolectric
private ResolveInfo resolvePreferredActivity(
Intent intent,
List<ResolveInfo> candidates,
SortedMap<ComponentName, List<IntentFilter>> preferredActivities) {
preferredActivities = mapForPackage(preferredActivities, intent.getPackage());
for (ResolveInfo candidate : candidates) {
ActivityInfo activityInfo = candidate.activityInfo;
if (!isValidComponentInfo(activityInfo)) {
continue;
}
ComponentName candidateName =
new ComponentName(activityInfo.applicationInfo.packageName, activityInfo.name);
List<IntentFilter> intentFilters = preferredActivities.get(candidateName);
if (intentFilters == null) {
continue;
}
for (IntentFilter filter : intentFilters) {
if ((filter.match(context.getContentResolver(), intent, false, "robo")
& MATCH_CATEGORY_MASK)
!= 0) {
return candidate;
}
}
}
return null;
}
代码示例来源:origin: tiann/understand-plugin-framework
activityInfo.applicationInfo.packageName = target.getPackage() == null ?
target.getComponent().getPackageName() : target.getPackage();
代码示例来源:origin: robolectric/robolectric
String package1 = i1.getPackage();
String package2 = i2.getPackage();
if (package1 == null && package2 != null) return -1;
if (package1 != null && package2 == null) return 1;
代码示例来源:origin: robolectric/robolectric
List<ResolveInfo> resolveInfoList = new ArrayList<>();
Map<ComponentName, List<IntentFilter>> filtersForPackage =
mapForPackage(filters, intent.getPackage());
components:
for (Map.Entry<ComponentName, List<IntentFilter>> componentEntry :
代码示例来源:origin: robolectric/robolectric
if (getComponentForIntent(intent) != null) {
packageName = getComponentForIntent(intent).getPackageName();
} else if (intent.getPackage() != null) {
packageName = intent.getPackage();
} else if (componentInfo.packageName != null) {
packageName = componentInfo.packageName;
代码示例来源:origin: android-hacker/VirtualXposed
final String action = intent.getAction();
final Uri data = intent.getData();
final String packageName = intent.getPackage();
代码示例来源:origin: oasisfeng/condom
@Override public ComponentName startService(final Intent service) {
return service.getComponent() != null ? service.getComponent() : new ComponentName(service.getPackage(), "A");
}
}, null);
代码示例来源:origin: oasisfeng/condom
@Override public ComponentName startService(final Intent service) {
return service.getComponent() != null ? service.getComponent() : new ComponentName(service.getPackage(), "A");
}
代码示例来源:origin: android-hacker/VirtualXposed
String pkgName = intent.getPackage();
if (pkgName == null) {
return mProviders.queryIntent(intent, resolvedType, flags, userId);
代码示例来源:origin: ACRA/acra
grantPermission(context, intent, intent.getPackage(), attachments);
代码示例来源:origin: android-hacker/VirtualXposed
String pkgName = intent.getPackage();
if (pkgName == null) {
return mServices.queryIntent(intent, resolvedType, flags, userId);
代码示例来源:origin: android-hacker/VirtualXposed
final String pkgName = intent.getPackage();
if (pkgName == null) {
return mActivities.queryIntent(intent, resolvedType, flags, userId);
代码示例来源:origin: android-hacker/VirtualXposed
String pkgName = intent.getPackage();
if (pkgName == null) {
return mReceivers.queryIntent(intent, resolvedType, flags, userId);
代码示例来源:origin: android-hacker/VirtualXposed
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();
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldFillIn() throws Exception {
Intent intentA = new Intent();
Intent intentB = new Intent();
intentB.setAction("foo");
Uri uri = Uri.parse("http://www.foo.com");
intentB.setDataAndType(uri, "text/html");
String category = "category";
intentB.addCategory(category);
intentB.setPackage("com.foobar.app");
ComponentName cn = new ComponentName("com.foobar.app", "fragmentActivity");
intentB.setComponent(cn);
intentB.putExtra("FOO", 23);
int flags = Intent.FILL_IN_ACTION |
Intent.FILL_IN_DATA |
Intent.FILL_IN_CATEGORIES |
Intent.FILL_IN_PACKAGE |
Intent.FILL_IN_COMPONENT;
int result = intentA.fillIn(intentB, flags);
assertEquals("foo", intentA.getAction());
assertSame(uri, intentA.getData());
assertEquals("text/html", intentA.getType());
assertTrue(intentA.getCategories().contains(category));
assertEquals("com.foobar.app", intentA.getPackage());
assertSame(cn, intentA.getComponent());
assertEquals(23, intentA.getIntExtra("FOO", -1));
assertEquals(result, flags);
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testShareToMessengerWith20150314Protocol() throws Exception {
setupPackageManagerForMessenger(true);
setupContentResolverForProtocolVersions(20150314);
Uri uri = Uri.parse("file:///foo.jpeg");
Uri externalUri = Uri.parse("http://example.com/foo.jpeg");
ShareToMessengerParams params = ShareToMessengerParams
.newBuilder(uri, "image/jpeg")
.setMetaData("{}")
.setExternalUri(externalUri)
.build();
MessengerUtils.shareToMessenger(mMockActivity, 1, params);
// Expect it to have launched messenger with the right intent.
ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mMockActivity).startActivityForResult(
intentArgumentCaptor.capture(),
eq(1));
Intent intent = intentArgumentCaptor.getValue();
assertEquals(Intent.ACTION_SEND, intent.getAction());
assertEquals(Intent.FLAG_GRANT_READ_URI_PERMISSION, intent.getFlags());
assertEquals("com.facebook.orca", intent.getPackage());
assertEquals(uri, intent.getParcelableExtra(Intent.EXTRA_STREAM));
assertEquals("image/jpeg", intent.getType());
assertEquals("200", intent.getStringExtra("com.facebook.orca.extra.APPLICATION_ID"));
assertEquals(20150314, intent.getIntExtra("com.facebook.orca.extra.PROTOCOL_VERSION", -1));
assertEquals("{}", intent.getStringExtra("com.facebook.orca.extra.METADATA"));
assertEquals(externalUri, intent.getParcelableExtra("com.facebook.orca.extra.EXTERNAL_URI"));
}
内容来源于网络,如有侵权,请联系作者删除!