@Test public void testCountDataTypes() throws Exception { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataType("image/*"); intentFilter.addDataType("audio/*"); assertThat(intentFilter.countDataTypes()).isEqualTo(2); } }
if (mimeType != null) { try { intentFilter.addDataType(mimeType); } catch (IntentFilter.MalformedMimeTypeException e) { throw new XmlPullParserException("bad mimeType", parser, e);
@Test public void matchData_NoMatchType() throws IntentFilter.MalformedMimeTypeException { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataType("image/testFail"); Uri uriTest1 = Uri.parse("http://testHost1:1"); assertThat(intentFilter.matchData("image/test", "http", uriTest1)) .isLessThan(0); }
@Test public void addDataType_shouldAddTheDataType() throws Exception { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataType("image/test"); assertThat(intentFilter.getDataType(0)).isEqualTo("image/test"); }
@Test public void matchData_MatchType() throws IntentFilter.MalformedMimeTypeException { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataType("image/test"); intentFilter.addDataScheme("http"); Uri uriTest1 = Uri.parse("http://testHost1:1"); assertThat(intentFilter.matchData("image/test", "http", uriTest1)) .isAtLeast(0); }
@Test public void matchData_MatchSchemeNoMatchType() throws IntentFilter.MalformedMimeTypeException { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataScheme("http"); intentFilter.addDataType("image/testFail"); Uri uriTest1 = Uri.parse("http://testHost1:1"); assertThat(intentFilter.matchData("image/test", "http", uriTest1)) .isLessThan(0); }
@Test public void matchData_NoMatchScheme() throws IntentFilter.MalformedMimeTypeException { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataScheme("http"); intentFilter.addDataType("image/test"); Uri uriTest1 = Uri.parse("https://testHost1:1"); assertThat(intentFilter.matchData("image/test", "https", uriTest1)) .isLessThan(0); }
@Test public void matchData_MatchAll() throws IntentFilter.MalformedMimeTypeException{ IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataType("image/test"); intentFilter.addDataScheme("http"); intentFilter.addDataAuthority("testHost1", "1"); Uri uriTest1 = Uri.parse("http://testHost1:1"); assertThat(intentFilter.matchData("image/test", "http", uriTest1)) .isAtLeast(0); }
@Test public void hasDataType() throws IntentFilter.MalformedMimeTypeException{ IntentFilter intentFilter = new IntentFilter(); assertThat(intentFilter.hasDataType("image/test")).isFalse(); intentFilter.addDataType("image/test"); assertThat(intentFilter.hasDataType("image/test")).isTrue(); }
@Test public void matchData_NoMatchDataAuthority() throws IntentFilter.MalformedMimeTypeException { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataType("image/test"); intentFilter.addDataScheme("http"); intentFilter.addDataAuthority("testHost1", "1"); Uri uriTest1 = Uri.parse("http://testHost1:2"); assertThat(intentFilter.matchData("image/test", "http", uriTest1)) .isLessThan(0); }
@Test public void matchData_MatchesPartialType() throws IntentFilter.MalformedMimeTypeException { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataScheme("content"); intentFilter.addDataType("image/*"); Uri uri = Uri.parse("content://authority/images"); assertThat(intentFilter.matchData("image/test", "content", uri)).isAtLeast(0); assertThat(intentFilter.matchData("video/test", "content", uri)).isLessThan(0); }
@Test public void matchData_MatchesAnyTypeAndSubtype() throws IntentFilter.MalformedMimeTypeException { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataScheme("content"); intentFilter.addDataType("*/*"); Uri uri = Uri.parse("content://authority/images"); assertThat(intentFilter.matchData("image/test", "content", uri)).isAtLeast(0); assertThat(intentFilter.matchData("image/*", "content", uri)).isAtLeast(0); assertThat(intentFilter.matchData("video/test", "content", uri)).isAtLeast(0); assertThat(intentFilter.matchData("video/*", "content", uri)).isAtLeast(0); }
if (mimeType != null) { try { filter.addDataType(mimeType); } catch (IntentFilter.MalformedMimeTypeException e) { VLog.w("ResolverActivity", "mimeType\n" + VLog.getStackTraceString(e));
@Test public void sendBroadcast_shouldOnlySendIntentWithTypeWhenReceiverMatchesType() throws IntentFilter.MalformedMimeTypeException { final BroadcastReceiver viewAllTypesReceiver = broadcastReceiver("ViewActionWithAnyTypeReceiver"); final IntentFilter allTypesIntentFilter = intentFilter("view"); allTypesIntentFilter.addDataType("*/*"); contextWrapper.registerReceiver(viewAllTypesReceiver, allTypesIntentFilter); final BroadcastReceiver imageReceiver = broadcastReceiver("ImageReceiver"); final IntentFilter imageIntentFilter = intentFilter("view"); imageIntentFilter.addDataType("img/*"); contextWrapper.registerReceiver(imageReceiver, imageIntentFilter); final BroadcastReceiver videoReceiver = broadcastReceiver("VideoReceiver"); final IntentFilter videoIntentFilter = intentFilter("view"); videoIntentFilter.addDataType("video/*"); contextWrapper.registerReceiver(videoReceiver, videoIntentFilter); final BroadcastReceiver viewReceiver = broadcastReceiver("ViewActionReceiver"); final IntentFilter viewIntentFilter = intentFilter("view"); contextWrapper.registerReceiver(viewReceiver, viewIntentFilter); final Intent imageIntent = new Intent("view"); imageIntent.setType("img/jpeg"); contextWrapper.sendBroadcast(imageIntent); final Intent videoIntent = new Intent("view"); videoIntent.setType("video/mp4"); contextWrapper.sendBroadcast(videoIntent); assertThat(transcript).containsExactly( "ViewActionWithAnyTypeReceiver notified of view", "ImageReceiver notified of view", "ViewActionWithAnyTypeReceiver notified of view", "VideoReceiver notified of view"); }
private static void addDataTypeUnchecked(IntentFilter filter, String type) { try { filter.addDataType(type); } catch (MalformedMimeTypeException ex) { throw new RuntimeException(ex); } }
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); ndef.addDataType("some/mimetype");
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); try { ndef.addDataType("*/*"); } catch (MalformedMimeTypeException e) { throw new RuntimeException("fail", e); } IntentFilter tech = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); try { tech.addDataType("*/*"); } catch (MalformedMimeTypeException e) { throw new RuntimeException("fail", e); } IntentFilter[] intentFiltersArray = new IntentFilter[] { tag, ndef, tech };
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); try { ndef.addDataType("*/*"); } catch (MalformedMimeTypeException e) {} nfcFilter = new IntentFilter[]{ ndef, new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED), new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED) };
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); try { ndef.addDataType("*/*"); /* Handles all MIME based dispatches. You should specify only the ones that you need. */ } catch (MalformedMimeTypeException e) { throw new RuntimeException("fail", e); } mFilters = new IntentFilter[] { ndef, }; mTechLists = new String[][] { new String[] { NfcF.class.getName() } }; NfcAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
// register activity monitor for the send mail activity Instrumentation instrumentation = getInstrumentation(); IntentFilter filter = new IntentFilter(Intent.ACTION_SENDTO); //Here you just need to say to your intent filter what exactly to look for filter.addDataType(CommonDataKinds.Email.CONTENT_TYPE); ActivityMonitor monitor = instrumentation.addMonitor(filter, null, true); // click on the "Send Feedback" button (use Robotium here) solo.clickOnButton(0); // wait for the send mail activity to start Activity currentActivity = instrumentation.waitForMonitorWithTimeout(monitor, 5000); assertNotNull(currentActivity);