protected SelfNotifiableSlot(@NonNull Context context) { super(context); filter = new IntentFilter(); filter.addAction(ACTION_SATISFIED); filter.addAction(ACTION_UNSATISFIED); filter.addCategory(CATEGORY_NOTIFY_SLOT); filter.addDataScheme(uri.getScheme()); filter.addDataAuthority(uri.getAuthority(), null); filter.addDataPath(uri.getPath(), PatternMatcher.PATTERN_LITERAL); Intent intent = new Intent(ACTION_SATISFIED); intent.addCategory(CATEGORY_NOTIFY_SLOT); intent.setData(uri); notifySelfIntent_positive = PendingIntent.getBroadcast(context, 0, intent, 0); intent.setAction(ACTION_UNSATISFIED); notifySelfIntent_negative = PendingIntent.getBroadcast(context, 0, intent, 0); }
/** * @param activity The activity that's requesting dispatch * @param adapter NfcAdapter for the current context */ private void enableForegroundDispatch(Activity activity, NfcAdapter adapter) { final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0); IntentFilter[] filters = new IntentFilter[1]; String[][] techList = new String[][]{}; // Notice that this is the same filter as in our manifest. filters[0] = new IntentFilter(); filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED); filters[0].addCategory(Intent.CATEGORY_DEFAULT); filters[0].addDataScheme("https"); filters[0].addDataAuthority(Constants.FLOW_DOMAIN, null); filters[0].addDataPath(".*", PatternMatcher.PATTERN_SIMPLE_GLOB); adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList); }
protected void setForegroundListener() { adapter = NfcAdapter.getDefaultAdapter(this); pi = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); IntentFilter old_ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); old_ndef.addDataScheme("vnd.android.nfc"); old_ndef.addDataAuthority("ext", null); old_ndef.addDataPath("/CryptoNFCKey", PatternMatcher.PATTERN_PREFIX); IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); ndef.addDataScheme("vnd.android.nfc"); ndef.addDataAuthority("ext", null); ndef.addDataPath("/r0ly.fr:CryptoNFCKey",PatternMatcher.PATTERN_PREFIX); intentFiltersArray = new IntentFilter[] {old_ndef, ndef}; }
private void setForegroundListener() { adapter = NfcAdapter.getDefaultAdapter(this); pi = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); IntentFilter old_ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); old_ndef.addDataScheme("vnd.android.nfc"); old_ndef.addDataAuthority("ext", null); old_ndef.addDataPath("/CryptoNFCKey", PatternMatcher.PATTERN_PREFIX); IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); ndef.addDataScheme("vnd.android.nfc"); ndef.addDataAuthority("ext", null); ndef.addDataPath("/r0ly.fr:CryptoNFCKey",PatternMatcher.PATTERN_PREFIX); intentFiltersArray = new IntentFilter[] {old_ndef, ndef}; }
@SuppressLint("NewApi") public NfcCommunicator(Activity activity, NetworkDaemon daemon) { super(activity, daemon); IntentFilter filter = new IntentFilter(); filter.addAction(NfcAdapter.ACTION_TAG_DISCOVERED); filter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED); filter.addAction(NfcAdapter.ACTION_TECH_DISCOVERED); // Filter for the custom external type as specified in // http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#ext-type // (This does not seem work as it does not exclude NDEF messages with a different type) filter.addDataScheme("vnd.android.nfc"); filter.addDataAuthority("ext", null); filter.addDataPath(extRecordDomain + ":" + extRecordType, PatternMatcher.PATTERN_PREFIX); mFilters = new IntentFilter[] { filter }; // Only consider NDEF-Tags mTechLists = new String[][] { new String[] { Ndef.class.getName() } }; setupActivityBasedVariables(activity); }
/** * Gets an {@link IntentFilter} for matching events from the install * process based on the original download URL as a {@link Uri}. */ public static IntentFilter getInstallIntentFilter(Uri uri) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Installer.ACTION_INSTALL_STARTED); intentFilter.addAction(Installer.ACTION_INSTALL_COMPLETE); intentFilter.addAction(Installer.ACTION_INSTALL_INTERRUPTED); intentFilter.addAction(Installer.ACTION_INSTALL_USER_INTERACTION); intentFilter.addDataScheme(uri.getScheme()); intentFilter.addDataAuthority(uri.getHost(), String.valueOf(uri.getPort())); intentFilter.addDataPath(uri.getPath(), PatternMatcher.PATTERN_LITERAL); return intentFilter; }
public static IntentFilter getUninstallIntentFilter(String packageName) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Installer.ACTION_UNINSTALL_STARTED); intentFilter.addAction(Installer.ACTION_UNINSTALL_COMPLETE); intentFilter.addAction(Installer.ACTION_UNINSTALL_INTERRUPTED); intentFilter.addAction(Installer.ACTION_UNINSTALL_USER_INTERACTION); intentFilter.addDataScheme("package"); intentFilter.addDataPath(packageName, PatternMatcher.PATTERN_LITERAL); return intentFilter; }
/** * Get a prepared {@link IntentFilter} for use for matching this service's action events. * * @param urlString The full file URL to match. */ public static IntentFilter getIntentFilter(String urlString) { Uri uri = Uri.parse(urlString); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Downloader.ACTION_STARTED); intentFilter.addAction(Downloader.ACTION_PROGRESS); intentFilter.addAction(Downloader.ACTION_COMPLETE); intentFilter.addAction(Downloader.ACTION_INTERRUPTED); intentFilter.addAction(Downloader.ACTION_CONNECTION_FAILED); intentFilter.addDataScheme(uri.getScheme()); intentFilter.addDataAuthority(uri.getHost(), String.valueOf(uri.getPort())); intentFilter.addDataPath(uri.getPath(), PatternMatcher.PATTERN_LITERAL); return intentFilter; }
/** * 获得 path 匹配类型 */ public int getPatternMatcherType() { if (TextUtils.isEmpty(pathPattern) && TextUtils.isEmpty(pathPattern)) { return PatternMatcher.PATTERN_LITERAL; } else if (!TextUtils.isEmpty(pathPrefix)) { return PatternMatcher.PATTERN_PREFIX; } else { return PatternMatcher.PATTERN_SIMPLE_GLOB; } }
/** * Get a prepared {@link IntentFilter} for use for matching this service's action events. * * @param urlString The full file URL to match. * @param action {@link Downloader#ACTION_STARTED}, {@link Downloader#ACTION_PROGRESS}, * {@link Downloader#ACTION_INTERRUPTED}, or {@link Downloader#ACTION_COMPLETE}, * @return */ public static IntentFilter getIntentFilter(String urlString, String action) { Uri uri = Uri.parse(urlString); IntentFilter intentFilter = new IntentFilter(action); intentFilter.addDataScheme(uri.getScheme()); intentFilter.addDataAuthority(uri.getHost(), String.valueOf(uri.getPort())); intentFilter.addDataPath(uri.getPath(), PatternMatcher.PATTERN_LITERAL); return intentFilter; }
public static IntentFilter updateChurchesFilter(@Nullable final String ministryId) { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_CHURCHES); if (ministryId == null) { addDataUri(filter, churchesUri(), PatternMatcher.PATTERN_PREFIX); } else { addDataUri(filter, churchesUri(ministryId), PatternMatcher.PATTERN_LITERAL); } return filter; }
public static IntentFilter updateTrainingFilter(@Nullable final String ministryId) { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_TRAINING); if (ministryId == null) { addDataUri(filter, trainingUri(), PatternMatcher.PATTERN_PREFIX); } else { addDataUri(filter, trainingUri(ministryId), PatternMatcher.PATTERN_LITERAL); } return filter; }
public static IntentFilter updateMeasurementValuesFilter(@NonNull final String ministryId, @NonNull final Mcc mcc, @NonNull final YearMonth period, @NonNull final String guid) { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_MEASUREMENT_VALUES); addDataUri(filter, measurementsUri(ministryId, mcc, period, guid), PatternMatcher.PATTERN_LITERAL); return filter; }
public static IntentFilter updateMeasurementDetailsFilter(@NonNull final String ministryId, @NonNull final Mcc mcc, @NonNull final YearMonth period, @NonNull final String guid, @NonNull final String permLink) { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_MEASUREMENT_DETAILS); addDataUri(filter, measurementsUri(ministryId, mcc, period, guid, permLink), PatternMatcher.PATTERN_LITERAL); return filter; }
public static IntentFilter updateFavoriteMeasurementsFilter(@NonNull final String guid, @NonNull final String ministryId, @NonNull final Mcc mcc) { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_FAVORITE_MEASUREMENTS); addDataUri(filter, measurementsUri(guid, ministryId, mcc), PatternMatcher.PATTERN_LITERAL); return filter; }
private static boolean equal_patterns(final Iterator<PatternMatcher> a, final Iterator<PatternMatcher> b) { if (a == b) return true; if (a == null || b == null) return false; while (a.hasNext()) { if (! b.hasNext()) return false; final PatternMatcher o1 = a.next(); final PatternMatcher o2 = b.next(); if (! equal(o1, o2)) return false; } return ! b.hasNext(); }
public PatternStringFilter(ValueProvider valueProvider, String attrValue) { super(valueProvider); mPattern = new PatternMatcher(attrValue, PatternMatcher.PATTERN_SIMPLE_GLOB); }
public static IntentFilter noAssignmentsFilter(@NonNull final String guid) { final IntentFilter filter = new IntentFilter(ACTION_NO_ASSIGNMENTS); addDataUri(filter, assignmentsUri(guid), PatternMatcher.PATTERN_LITERAL); return filter; }
public static IntentFilter updateAssignmentsFilter() { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_ASSIGNMENTS); addDataUri(filter, assignmentsUri(), PatternMatcher.PATTERN_PREFIX); return filter; }
public static IntentFilter updateAssignmentsFilter(@NonNull final String guid) { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_ASSIGNMENTS); addDataUri(filter, assignmentsUri(guid), PatternMatcher.PATTERN_LITERAL); return filter; }
public static IntentFilter updateMinistriesFilter() { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_MINISTRIES); addDataUri(filter, ministriesUri(), PatternMatcher.PATTERN_LITERAL); return filter; }
public static IntentFilter updateMeasurementValuesFilter(@NonNull final String ministryId, @NonNull final Mcc mcc, @NonNull final YearMonth period) { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_MEASUREMENT_VALUES); addDataUri(filter, measurementsUri(ministryId, mcc, period), PatternMatcher.PATTERN_PREFIX); return filter; }
public static IntentFilter updateStoriesFilter() { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_STORIES); addDataUri(filter, URI_STORIES, PatternMatcher.PATTERN_LITERAL); return filter; }
public static IntentFilter updatePreferencesFilter(@NonNull final String guid) { final IntentFilter filter = new IntentFilter(ACTION_UPDATE_PREFERENCES); addDataUri(filter, preferencesUri(guid), PatternMatcher.PATTERN_LITERAL); return filter; }
public static void addDataUri(@NonNull final IntentFilter filter, @NonNull final Uri uri) { addDataUri(filter, uri, PatternMatcher.PATTERN_LITERAL); }
public static boolean hasDataPath(IntentFilter f2, PatternMatcher dataPath) { // TODO Auto-generated method stub return false; }
public static boolean hasDataSchemeSpecificPart(IntentFilter f2, PatternMatcher dataSchemeSpecificPart) { // TODO Auto-generated method stub return false; }
public IntentFilter toIntentFilter(int type) { if (1 == type) { return toIntentFilter(); } IntentFilter filter = toIntentFilter(); try { //for mimetype if (type >= 1) { if (! StringUtil.isEmpty(dataAndType.getType())) { if (! StringUtil.isEmpty(dataAndType.getSubtype())) { filter.addDataType(dataAndType.getType() + "/" + dataAndType.getSubtype()); filterType = 2; } else { filter.addDataType(dataAndType.getType()); filterType = 2; } } } //for data if (type >= 2) { if (! StringUtil.isEmpty(dataAndType.getHost())) { if (! StringUtil.isEmpty(dataAndType.getPort())) { filter.addDataAuthority(dataAndType.getHost(), dataAndType.getPort()); } else { filter.addDataAuthority(dataAndType.getHost(), null); } filterType = 3; } if (! StringUtil.isEmpty(dataAndType.getPath())) { filter.addDataPath(dataAndType.getPath(), PatternMatcher.PATTERN_LITERAL); filterType = 3; } if (! StringUtil.isEmpty(dataAndType.getScheme())) { filter.addDataScheme(dataAndType.getScheme()); filterType = 3; } } } catch (Exception ex) { ex.printStackTrace(); } return filter; }
private boolean matchIntentFilter(ActivityData activityData, Intent intent) { for (IntentFilterData intentFilterData : activityData.getIntentFilters()) { List<String> actionList = intentFilterData.getActions(); List<String> categoryList = intentFilterData.getCategories(); IntentFilter intentFilter = new IntentFilter(); for (String action : actionList) { intentFilter.addAction(action); } for (String category : categoryList) { intentFilter.addCategory(category); } for (String scheme : intentFilterData.getSchemes()) { intentFilter.addDataScheme(scheme); } for (String mimeType : intentFilterData.getMimeTypes()) { try { intentFilter.addDataType(mimeType); } catch (IntentFilter.MalformedMimeTypeException ex) { throw new RuntimeException(ex); } } for (String path : intentFilterData.getPaths()) { intentFilter.addDataPath(path, PatternMatcher.PATTERN_LITERAL); } for (String pathPattern : intentFilterData.getPathPatterns()) { intentFilter.addDataPath(pathPattern, PatternMatcher.PATTERN_SIMPLE_GLOB); } for (String pathPrefix : intentFilterData.getPathPrefixes()) { intentFilter.addDataPath(pathPrefix, PatternMatcher.PATTERN_PREFIX); } for (IntentFilterData.DataAuthority authority : intentFilterData.getAuthorities()) { intentFilter.addDataAuthority(authority.getHost(), authority.getPort()); } // match action boolean matchActionResult = intentFilter.matchAction(intent.getAction()); // match category String matchCategoriesResult = intentFilter.matchCategories(intent.getCategories()); // match data int matchResult = intentFilter.matchData(intent.getType(), (intent.getData() != null ? intent.getData().getScheme() : null), intent.getData()); if (matchActionResult && (matchCategoriesResult == null) && (matchResult != IntentFilter.NO_MATCH_DATA && matchResult != IntentFilter.NO_MATCH_TYPE)){ return true; } } return false; }
static void dumpIntentFilter(FormattedTextBuilder ftb, IntentFilter filter, Resources res, boolean isBroadcast) { int tagColor = res.getColor(R.color.xml_tag); int attributeNameColor = res.getColor(R.color.xml_attr_name); int attributeValueColor = res.getColor(R.color.xml_attr_value); int commentColor = res.getColor(R.color.xml_comment); final String protectedComment = " <!-- " + res.getString(R.string.broadcast_action_protected_comment) + " -->"; ftb.appendColoured("\n<intent-filter>", tagColor); for (int i = 0, j = filter.countActions(); i < j; i++) { final String action = filter.getAction(i); ftb.appendColoured("\n <action", tagColor); ftb.appendColoured(" a:name=", attributeNameColor); ftb.appendColoured("\"" + action + "\"", attributeValueColor); ftb.appendColoured(">", tagColor); if (isBroadcast && Utils.isProtectedBroadcast(action)) { ftb.appendColoured(protectedComment, commentColor); } } for (int i = 0, j = filter.countCategories(); i < j; i++) { ftb.appendColoured("\n <category", tagColor); ftb.appendColoured(" a:name=", attributeNameColor); ftb.appendColoured("\"" + filter.getCategory(i) + "\"", attributeValueColor); ftb.appendColoured(">", tagColor); } for (int i = 0, j = filter.countDataSchemes(); i < j; i++) { ftb.appendColoured("\n <data", tagColor); ftb.appendColoured(" a:scheme=", attributeNameColor); ftb.appendColoured("\"" + filter.getDataScheme(i) + "\"", attributeValueColor); ftb.appendColoured(">", tagColor); } for (int i = 0, j = filter.countDataAuthorities(); i < j; i++) { IntentFilter.AuthorityEntry authority = filter.getDataAuthority(i); ftb.appendColoured("\n <data", tagColor); ftb.appendColoured(" a:host=", attributeNameColor); ftb.appendColoured("\"" + authority.getHost() + "\"", attributeValueColor); if (authority.getPort() != -1) { ftb.appendColoured(" a:port=", attributeNameColor); ftb.appendColoured("\"" + authority.getPort() + "\"", attributeValueColor); } ftb.appendColoured(">", tagColor); } for (int i = 0, j = filter.countDataPaths(); i < j; i++) { PatternMatcher pathMatcher = filter.getDataPath(i); int type = pathMatcher.getType(); ftb.appendColoured("\n <data", tagColor); ftb.appendColoured(" a:path" + ( type == PatternMatcher.PATTERN_LITERAL ? "" : type == PatternMatcher.PATTERN_PREFIX ? "Prefix" : type == PatternMatcher.PATTERN_SIMPLE_GLOB ? "Pattern" : "[unknown]" ) + "=", attributeNameColor); ftb.appendColoured("\"" + pathMatcher.getPath() + "\"", attributeValueColor); ftb.appendColoured(">", tagColor); } for (int i = 0, j = filter.countDataTypes(); i < j; i++) { String dataType = filter.getDataType(i); if (!dataType.contains("/")) { // IntentFilter for partial types don't store "/*" at end // e.g. "image" instead of "image/*". // We display it in full form here dataType += "/*"; } ftb.appendColoured("\n <data", tagColor); ftb.appendColoured(" a:mimeType=", attributeNameColor); ftb.appendColoured("\"" + dataType + "\"", attributeValueColor); ftb.appendColoured(">", tagColor); } ftb.appendColoured("\n</intent-filter>", tagColor); }
private static boolean equal(final PatternMatcher a, final PatternMatcher b) { return a == b || (a != null && b != null && a.getType() == b.getType() && equal(a.getPath(), b.getPath())); }
public static IntentFilter getCompletionFilter( String taskName ) { IntentFilter filter = new IntentFilter( TaskerIntent.ACTION_TASK_COMPLETE ); filter.addDataScheme( TASK_NAME_DATA_SCHEME ); filter.addDataPath( taskName, PatternMatcher.PATTERN_LITERAL ); return filter; }
public static IntentFilter getCompletionFilter(String taskName) { IntentFilter filter = new IntentFilter(TaskerIntent.ACTION_TASK_COMPLETE); filter.addDataScheme(TASK_NAME_DATA_SCHEME); filter.addDataPath(taskName, PatternMatcher.PATTERN_LITERAL); return filter; }