@Test public void matchDataAuthority_matchHostWithNoPort() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataAuthority("testHost1", "-1"); intentFilter.addDataAuthority("testHost2", "-1"); Uri uriTest1 = Uri.parse("http://testHost1:100"); Uri uriTest2 = Uri.parse("http://testHost2:200"); assertThat(intentFilter.matchDataAuthority(uriTest1)).isEqualTo(IntentFilter.MATCH_CATEGORY_HOST); assertThat(intentFilter.matchDataAuthority(uriTest2)).isEqualTo(IntentFilter.MATCH_CATEGORY_HOST); }
final String port = parser.getAttributeValue(null, "port"); if (host != null) { intentFilter.addDataAuthority(host, port);
@Test public void matchDataAuthority_matchHostAndPort() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataAuthority("testHost1", "1"); intentFilter.addDataAuthority("testHost2", "2"); Uri uriTest1 = Uri.parse("http://testHost1:1"); Uri uriTest2 = Uri.parse("http://testHost2:2"); assertThat(intentFilter.matchDataAuthority(uriTest1)).isEqualTo(IntentFilter.MATCH_CATEGORY_PORT); assertThat(intentFilter.matchDataAuthority(uriTest2)).isEqualTo(IntentFilter.MATCH_CATEGORY_PORT); }
@Test public void matchDataAuthority_NoMatch() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataAuthority("testHost1", "1"); intentFilter.addDataAuthority("testHost2", "2"); // Port doesn't match Uri uriTest1 = Uri.parse("http://testHost1:2"); // Host doesn't match Uri uriTest2 = Uri.parse("http://testHost3:2"); assertThat(intentFilter.matchDataAuthority(uriTest1)).isEqualTo( IntentFilter.NO_MATCH_DATA); assertThat(intentFilter.matchDataAuthority(uriTest2)).isEqualTo( IntentFilter.NO_MATCH_DATA); }
@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_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 addDataAuthority_shouldAddTheDataAuthority() throws Exception { IntentFilter intentFilter = new IntentFilter(); intentFilter.addDataAuthority("test.com", "8080"); intentFilter.addDataAuthority("example.com", "42"); assertThat(intentFilter.getDataAuthority(0).getHost()).isEqualTo("test.com"); assertThat(intentFilter.getDataAuthority(0).getPort()).isEqualTo(8080); assertThat(intentFilter.getDataAuthority(1).getHost()).isEqualTo("example.com"); assertThat(intentFilter.getDataAuthority(1).getPort()).isEqualTo(42); }
if (a.match(data) >= 0) { int port = a.getPort(); filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null); break;
/** * Builds an intent filter to listen out for calendar events being added or removed * * @return the intent filter */ private IntentFilter getCalendarEventsIntentFilter() { IntentFilter filter = new IntentFilter("android.intent.action.PROVIDER_CHANGED"); filter.addDataScheme("content"); filter.addDataAuthority("com.google.android.wearable.provider.calendar", null); return filter; }
IntentFilter filter = new IntentFilter(SMS_RECIEVED); filter.addDataAuthority("*", "8091"); filter.addDataScheme("sms"); //use the filter, etc...
private void sendSMS() { BinarySMSReceiver smsReceiver = null; smsReceiver = new BinarySMSReceiver(); smsReceiver.setActivityHandler(this); IntentFilter portIntentFilter = new IntentFilter("android.intent.action.DATA_SMS_RECEIVED"); portIntentFilter.addDataAuthority("*", "9512"); portIntentFilter.addDataScheme("sms"); registerReceiver(smsReceiver, portIntentFilter); String messageText = etMobile.getText().toString().trim(); short SMS_PORT = 9512; SmsManager smsManager = SmsManager.getDefault(); smsManager.sendDataMessage(etMobile.getText().toString().trim(), null, SMS_PORT, messageText.getBytes(), null, null); }
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); ndef.addDataScheme("http"); ndef.addDataAuthority("www.example.com", null);
private static void registerReceivers(Context contextIn) { if (receiversRegistered) return; Context context = contextIn.getApplicationContext(); EnvironmentChangedReceiver receiver = new EnvironmentChangedReceiver(); IntentFilter providerChanged = new IntentFilter(); providerChanged.addAction("android.intent.action.PROVIDER_CHANGED"); providerChanged.addDataScheme("content"); providerChanged.addDataAuthority("com.android.calendar", null); context.registerReceiver(receiver, providerChanged); IntentFilter userPresent = new IntentFilter(); userPresent.addAction("android.intent.action.USER_PRESENT"); context.registerReceiver(receiver, userPresent); Log.i(EventAppWidgetProvider.class.getName(), "Registered receivers from " + contextIn.getClass().getName()); receiversRegistered = true; } }
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); ndef.addDataScheme("vnd.android.nfc"); ndef.addDataAuthority("ext", null); ndef.addDataPath("/com.example:sometype", PatternMatcher.PATTERN_PREFIX);
IntentFilter ifilter = new IntentFilter("com.your.package.ACTION_TWITTER_MSG"); ifilter.addDataScheme("twitter"); ifilter.addDataAuthority("com.your.package", null); ifilter.addDataPath("/foo", PatternMatcher.PATTERN_PREFIX);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); ndef.addDataScheme("vnd.android.nfc"); ndef.addDataAuthority("ext", null); ndef.addDataPath("/com.example:mytype", PatternMatcher.PATTERN_PREFIX); IntentFilter[] intentFiltersArray = new IntentFilter[] { ndef, };
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); ndef.addDataScheme("http"); ndef.addDataAuthority("somehost.example.com", null); ndef.addDataPath("/somepath", PatternMatcher.PATTERN_PREFIX);
private NfcAdapter nfcAdapter; private PendingIntent mPendingIntent; private IntentFilter[] mFilters; private String[][] mTechLists; protected void onCreate(Bundle savedInstanceState) nfcAdapter = NfcAdapter.getDefaultAdapter(this); mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); IntentFilter ndefPkg = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); try { ndefPkg.addDataScheme("vnd.android.nfc"); ndefPkg.addDataAuthority("ext", null); ndefPkg.addDataPath("/android.com:pkg", 0); } catch (Exception e) { e.printStackTrace(); } mFilters = new IntentFilter[] {ndefPkg; mTechLists = new String[][] { new String[] { NfcF.class.getName() } }; } protected void onResume() { super.onResume(); nfcAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists); } protected void onPause() { super.onPause(); nfcAdapter.disableForegroundDispatch(this); }
new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); tagIntentFilter.addDataScheme("http"); tagIntentFilter.addDataAuthority("blog.radioactiveyak.com", null); mIntentFiltersArray = new IntentFilter[] { tagIntentFilter };
intentFilter.addDataAuthority(authority.getHost(), authority.getPort());