本文整理了Java中android.content.Intent.getType()
方法的一些代码示例,展示了Intent.getType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.getType()
方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:getType
暂无
代码示例来源:origin: robolectric/robolectric
private static int matchIntentFilter(Intent intent, IntentFilter intentFilter) {
return intentFilter.match(
intent.getAction(),
intent.getType(),
intent.getScheme(),
intent.getData(),
intent.getCategories(),
TAG);
}
代码示例来源:origin: square/assertj-android
public IntentAssert hasType(String type) {
isNotNull();
String actualType = actual.getType();
assertThat(actualType) //
.overridingErrorMessage("Expected type <%s> but was <%s>.", type, actualType) //
.isEqualTo(type);
return this;
}
代码示例来源:origin: android-hacker/VirtualXposed
public ServiceInfo resolveServiceInfo(Intent intent, int userId) {
ServiceInfo serviceInfo = null;
ResolveInfo resolveInfo = VPackageManager.get().resolveService(intent, intent.getType(), 0, userId);
if (resolveInfo != null) {
serviceInfo = resolveInfo.serviceInfo;
}
return serviceInfo;
}
代码示例来源:origin: robolectric/robolectric
/** Returns the BroadcaseReceivers wrappers, matching intent's action and permissions. */
private List<Wrapper> getAppropriateWrappers(Intent intent, String receiverPermission) {
broadcastIntents.add(intent);
List<Wrapper> result = new ArrayList<>();
List<Wrapper> copy = new ArrayList<>();
copy.addAll(registeredReceivers);
for (Wrapper wrapper : copy) {
if (hasMatchingPermission(wrapper.broadcastPermission, receiverPermission)
&& wrapper.intentFilter.matchAction(intent.getAction())) {
final int match =
wrapper.intentFilter.matchData(intent.getType(), intent.getScheme(), intent.getData());
if (match != IntentFilter.NO_MATCH_DATA && match != IntentFilter.NO_MATCH_TYPE) {
result.add(wrapper);
}
}
}
return result;
}
代码示例来源:origin: commonsguy/cw-omnibus
private void raiseNotification(Intent inbound, File output,
Exception e) {
NotificationCompat.Builder b=
new NotificationCompat.Builder(this, CHANNEL_WHATEVER);
b.setAutoCancel(true).setWhen(System.currentTimeMillis());
if (e == null) {
b.setContentTitle(getString(R.string.download_complete))
.setContentText(getString(R.string.fun))
.setSmallIcon(android.R.drawable.stat_sys_download_done);
Intent outbound=new Intent(Intent.ACTION_VIEW);
Uri outputUri=
FileProvider.getUriForFile(this, AUTHORITY, output);
outbound.setDataAndType(outputUri, inbound.getType());
outbound.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
PendingIntent pi=PendingIntent.getActivity(this, 0,
outbound, PendingIntent.FLAG_UPDATE_CURRENT);
b.setContentIntent(pi);
}
else {
b.setContentTitle(getString(R.string.exception))
.setContentText(e.getMessage())
.setSmallIcon(android.R.drawable.stat_notify_error);
}
NotificationManager mgr=
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
mgr.notify(NOTIFY_ID, b.build());
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected boolean sendBroadcast(Intent intent) {
boolean sent = false;
sentBroadcastIntents.add(intent);
List<Wrapper> copy = new ArrayList<>();
copy.addAll(registeredReceivers);
for (Wrapper wrapper : copy) {
if (wrapper.intentFilter.matchAction(intent.getAction())) {
final int match = wrapper.intentFilter.matchData(intent.getType(), intent.getScheme(), intent.getData());
if (match != IntentFilter.NO_MATCH_DATA && match != IntentFilter.NO_MATCH_TYPE) {
sent = true;
final BroadcastReceiver receiver = wrapper.broadcastReceiver;
final Intent broadcastIntent = intent;
Robolectric.getForegroundThreadScheduler().post(new Runnable() {
@Override
public void run() {
receiver.onReceive(RuntimeEnvironment.application, broadcastIntent);
}
});
}
}
}
return sent;
}
代码示例来源:origin: Tencent/tinker
final String componentName = item.getKey();
final IntentFilter intentFilter = item.getValue();
final int matchRes = intentFilter.match(intent.getAction(), intent.getType(),
intent.getScheme(), intent.getData(), intent.getCategories(), TAG);
final boolean matches = (matchRes != IntentFilter.NO_MATCH_ACTION)
代码示例来源:origin: termux/termux-app
final String type = intent.getType();
final String scheme = intent.getScheme();
代码示例来源:origin: commonsguy/cw-omnibus
super.onCreate(savedInstanceState);
String type=getIntent().getType();
Uri.Builder builder=PROVIDER
.buildUpon()
代码示例来源:origin: robolectric/robolectric
@Test
public void testSetType() throws Exception {
Intent intent = new Intent();
intent.setData(Uri.parse("content://this/and/that"));
assertSame(intent, intent.setType("def"));
assertNull(intent.getData());
assertEquals("def", intent.getType());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSetData() throws Exception {
Intent intent = new Intent();
Uri uri = Uri.parse("content://this/and/that");
intent.setType("abc");
assertSame(intent, intent.setData(uri));
assertSame(uri, intent.getData());
assertNull(intent.getType());
}
代码示例来源:origin: android-hacker/VirtualXposed
public synchronized ActivityInfo resolveActivityInfo(Intent intent, int userId) {
ActivityInfo activityInfo = null;
if (intent.getComponent() == null) {
ResolveInfo resolveInfo = VPackageManager.get().resolveIntent(intent, intent.getType(), 0, userId);
if (resolveInfo != null && resolveInfo.activityInfo != null) {
activityInfo = resolveInfo.activityInfo;
intent.setClassName(activityInfo.packageName, activityInfo.name);
}
} else {
activityInfo = resolveActivityInfo(intent.getComponent(), userId);
}
if (activityInfo != null) {
if (activityInfo.targetActivity != null) {
ComponentName componentName = new ComponentName(activityInfo.packageName, activityInfo.targetActivity);
activityInfo = VPackageManager.get().getActivityInfo(componentName, 0, userId);
intent.setComponent(componentName);
}
}
return activityInfo;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSetDataAndType() throws Exception {
Intent intent = new Intent();
Uri uri = Uri.parse("content://this/and/that");
assertSame(intent, intent.setDataAndType(uri, "ghi"));
assertSame(uri, intent.getData());
assertEquals("ghi", intent.getType());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void inflate_shouldParseIntentContainedInPreference() throws Exception {
final PreferenceScreen screen = inflatePreferenceActivity();
final Preference intentPreference = screen.findPreference("intent");
Intent intent = intentPreference.getIntent();
assertThat(intent).isNotNull();
assertThat(intent.getAction()).isEqualTo("action");
assertThat(intent.getData()).isEqualTo(Uri.parse("tel://1235"));
assertThat(intent.getType()).isEqualTo("application/text");
assertThat(intent.getComponent().getClassName()).isEqualTo("org.robolectric.test.Intent");
assertThat(intent.getComponent().getPackageName()).isEqualTo("org.robolectric");
}
代码示例来源:origin: seven332/EhViewer
String type = intent.getType();
if ("text/plain".equals(type)) {
ListUrlBuilder builder = new ListUrlBuilder();
代码示例来源:origin: android-hacker/VirtualXposed
return false;
if (!ObjectsCompat.equals(a.getType(), b.getType())) {
return false;
代码示例来源: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
assertEquals("thread_token", intent.getStringExtra("com.facebook.orca.extra.THREAD_TOKEN"));
assertEquals(uri, intent.getData());
assertEquals("image/jpeg", intent.getType());
assertEquals("200", intent.getStringExtra("com.facebook.orca.extra.APPLICATION_ID"));
assertEquals("{}", intent.getStringExtra("com.facebook.orca.extra.METADATA"));
代码示例来源: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"));
}
代码示例来源:origin: android-hacker/VirtualXposed
private void realStartActivityLocked(IBinder resultTo, Intent intent, String resultWho, int requestCode,
Bundle options) {
Class<?>[] types = mirror.android.app.IActivityManager.startActivity.paramList();
Object[] args = new Object[types.length];
if (types[0] == IApplicationThread.TYPE) {
args[0] = ActivityThread.getApplicationThread.call(VirtualCore.mainThread());
}
int intentIndex = ArrayUtils.protoIndexOf(types, Intent.class);
int resultToIndex = ArrayUtils.protoIndexOf(types, IBinder.class, 2);
int optionsIndex = ArrayUtils.protoIndexOf(types, Bundle.class);
int resolvedTypeIndex = intentIndex + 1;
int resultWhoIndex = resultToIndex + 1;
int requestCodeIndex = resultToIndex + 2;
args[intentIndex] = intent;
args[resultToIndex] = resultTo;
args[resultWhoIndex] = resultWho;
args[requestCodeIndex] = requestCode;
if (optionsIndex != -1) {
args[optionsIndex] = options;
}
args[resolvedTypeIndex] = intent.getType();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
args[intentIndex - 1] = VirtualCore.get().getHostPkg();
}
ClassUtils.fixArgs(types, args);
mirror.android.app.IActivityManager.startActivity.call(ActivityManagerNative.getDefault.call(),
(Object[]) args);
}
内容来源于网络,如有侵权,请联系作者删除!