List of usage examples for android.content IntentFilter getAction
public final String getAction(int index)
From source file:com.github.michalbednarski.intentslab.browser.ComponentInfoFragment.java
static CharSequence dumpIntentFilter(IntentFilter filter, Resources res, boolean isBroadcast) { FormattedTextBuilder ftb = new FormattedTextBuilder(); 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); }/*from w w w . ja v a 2 s . c o m*/ } 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); return ftb.getText(); }
From source file:com.sbhstimetable.sbhs_timetable_android.BelltimesFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); IntentFilter i = new IntentFilter(); i.addAction(ApiAccessor.ACTION_NOTICES_JSON); i.addAction(ApiAccessor.ACTION_BELLTIMES_JSON); i.addAction(ApiAccessor.ACTION_TODAY_JSON); i.addAction(ApiAccessor.ACTION_BELLTIMES_FAILED); Log.i("belltimesFragment", "I want " + i.getAction(3)); if (this.listener == null) { this.listener = new BroadcastListener(this); }/*w w w .j a v a 2 s.c o m*/ LocalBroadcastManager.getInstance(this.getActivity()).registerReceiver(this.listener, i); try { mListener = (CommonFragmentInterface) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement CommonFragmentInterface"); } }
From source file:com.github.michalbednarski.intentslab.ReceiveBroadcastService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { // Flag us as running sIsRunning = true;//from www .jav a 2 s. c o m // Prepare receiver and unregister old one if exist if (mReceiver != null) { // We were already started, clear old receiver unregisterReceiver(mReceiver); } else { mReceiver = new MyBroadcastReceiver(); } if (intent.getBooleanExtra("multiple", false)) { sReceivedBroadcasts = new ArrayList<ReceivedBroadcast>(); } else { sReceivedBroadcasts = null; } // Get IntentFilter and register receiver String action = ""; Parcelable[] filters = intent.getParcelableArrayExtra("intentFilters"); if (filters == null || filters.length == 0) { stopSelf(); return START_NOT_STICKY; } for (Parcelable uncastedFilter : filters) { IntentFilter filter = (IntentFilter) uncastedFilter; registerReceiver(mReceiver, filter); if (filters.length == 1) { if (filter.countActions() == 1) { action = filter.getAction(0); } } } // Show notification if (sReceivedBroadcasts != null) { showListeningMultipleNotification(); } else { showWaitingNotification(action); } return START_NOT_STICKY; }
From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java
private void setupActionSpinnerOrField() { IntentFilter[] intentFilters = getIntentEditor().getAttachedIntentFilters(); if (intentFilters != null) { // Build action set Set<String> actionSet = new HashSet<String>(); for (IntentFilter filter : intentFilters) { for (int i = 0, j = filter.countActions(); i < j; i++) { actionSet.add(filter.getAction(i)); }/*from w w w . j a v a 2 s . c om*/ } // Check if we have any action and if not (invalid intent-filter) // switch to textfield if (actionSet.isEmpty()) { setupActionField(); return; } // Convert action set to array mAvailbleActions = actionSet.toArray(new String[actionSet.size()]); Arrays.sort(mAvailbleActions); // Select current action String action = mEditedIntent.getAction(); if (action == null) { action = Intent.ACTION_VIEW; } int position = Arrays.binarySearch(mAvailbleActions, action); mActionsSpinner.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, mAvailbleActions)); if (position < 0) { position = 0; } mActionsSpinner.setSelection(position); // Show spinner and hide textfield mActionText.setVisibility(View.GONE); mActionsSpinner.setVisibility(View.VISIBLE); // Set listener for action change to refresh intent filter mActionsSpinner.setOnItemSelectedListener(this); } else { setupActionField(); } }
From source file:com.landenlabs.all_devtool.PackageFragment.java
/** * Get info on the preferred (launch by default) applications. * @return/*from www .j a v a2 s . co m*/ */ public String getPreferredAppInfo() { List<PackageInfo> packages = getActivity().getPackageManager().getInstalledPackages(0); List<IntentFilter> filters = new ArrayList<IntentFilter>(); List<ComponentName> activities = new ArrayList<ComponentName>(); String info = ""; int nPref = 0, nFilters = 0, nActivities = 0; PackageInfo packInfo = null; // int orderCnt = 0; for (int i = 0; i < packages.size(); i++) { packInfo = packages.get(i); nPref = getActivity().getPackageManager().getPreferredActivities(filters, activities, packInfo.packageName); nFilters = filters.size(); nActivities = activities.size(); if (nPref > 0 || nFilters > 0 || nActivities > 0) { // This is a launch by default package // info += "\n" + packInfo.packageName + "\n"; ArrayListPairString pkgList = new ArrayListPairString(); for (IntentFilter filter : filters) { info += "IntentFilter:\n"; for (int j = 0; j < filter.countActions(); j++) { addList(pkgList, "Action", filter.getAction(j)); } for (int j = 0; j < filter.countCategories(); j++) { addList(pkgList, "Category", filter.getCategory(j)); } for (int j = 0; j < filter.countDataTypes(); j++) { addList(pkgList, "Type", filter.getDataType(j)); } for (int j = 0; j < filter.countDataAuthorities(); j++) { addList(pkgList, "Authority", filter.getDataAuthority(j).toString()); } for (int j = 0; j < filter.countDataPaths(); j++) { addList(pkgList, "Path", filter.getDataPath(j).toString()); } for (int j = 0; j < filter.countDataSchemes(); j++) { addList(pkgList, "Scheme", filter.getDataScheme(j)); } // for (ComponentName activity : activities) { // info += "activity=" // + activity.flattenToString() + "\n"; // } } if (pkgList.size() != 0) { m_workList.add(new PackingItem(packInfo.packageName, pkgList, packInfo, i, packInfo.applicationInfo.processName)); } } } return info; }