List of usage examples for android.content IntentFilter hasAction
public final boolean hasAction(String action)
From source file:com.linkbubble.MainApplication.java
public static void openAppStore(Context context, String url) { PackageManager manager = context.getPackageManager(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(url));// w w w . jav a 2 s. c om List<ResolveInfo> infos = manager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); for (ResolveInfo info : infos) { IntentFilter filter = info.filter; if (filter != null && filter.hasAction(Intent.ACTION_VIEW) && filter.hasCategory(Intent.CATEGORY_BROWSABLE)) { if (info.activityInfo.packageName.equals(BuildConfig.STORE_PACKAGE)) { MainApplication.loadIntent(context, info.activityInfo.packageName, info.activityInfo.name, url, -1, true); return; } } } }
From source file:com.linkbubble.MainApplication.java
public static Intent getStoreIntent(Context context, String storeProUrl) { PackageManager manager = context.getPackageManager(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(storeProUrl)); List<ResolveInfo> infos = manager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); for (ResolveInfo info : infos) { IntentFilter filter = info.filter; if (filter != null && filter.hasAction(Intent.ACTION_VIEW) && filter.hasCategory(Intent.CATEGORY_BROWSABLE)) { if (info.activityInfo.packageName.equals(BuildConfig.STORE_PACKAGE)) { Intent result = new Intent(Intent.ACTION_VIEW); result.setClassName(info.activityInfo.packageName, info.activityInfo.name); result.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); result.setData(Uri.parse(storeProUrl)); return result; }//from w w w . j a v a2 s. co m } } return null; }
From source file:widgets.PageWidget.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); wv = (WebView) super.getActivity().findViewById(activity.getActId()); // get the location data String url = course.getLocation() + activity.getLocation(prefs.getString(super.getActivity().getString(R.string.prefs_language), Locale.getDefault().getLanguage())); try {//from ww w.jav a2 s. co m wv.loadDataWithBaseURL("file://" + course.getLocation() + "/", FileUtils.readFile(url), "text/html", "utf-8", null); } catch (IOException e) { wv.loadUrl("file://" + url); } // set up the page to intercept videos wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.contains("/video/")) { Log.d(TAG, "Intercepting click on video url: " + url); // extract video name from url int startPos = url.indexOf("/video/") + 7; mediaFileName = url.substring(startPos, url.length()); // check video file exists boolean exists = FileUtils.mediaFileExists(mediaFileName); if (!exists) { Toast.makeText(PageWidget.super.getActivity(), PageWidget.super.getActivity() .getString(R.string.error_media_not_found, mediaFileName), Toast.LENGTH_LONG) .show(); return true; } String mimeType = FileUtils.getMimeType(MobileLearning.MEDIA_PATH + mediaFileName); if (!FileUtils.supportedMediafileType(mimeType)) { Toast.makeText(PageWidget.super.getActivity(), PageWidget.super.getActivity() .getString(R.string.error_media_unsupported, mediaFileName), Toast.LENGTH_LONG) .show(); return true; } // check user has app installed to play the video // launch intent to play video Intent intent = new Intent(android.content.Intent.ACTION_VIEW); Uri data = Uri.parse(MobileLearning.MEDIA_PATH + mediaFileName); intent.setDataAndType(data, "video/mp4"); PackageManager pm = PageWidget.super.getActivity().getPackageManager(); List<ResolveInfo> infos = pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); boolean appFound = false; for (ResolveInfo info : infos) { IntentFilter filter = info.filter; if (filter != null && filter.hasAction(Intent.ACTION_VIEW)) { // Found an app with the right intent/filter appFound = true; } } if (!appFound) { Toast.makeText(PageWidget.super.getActivity(), PageWidget.super.getActivity().getString(R.string.error_media_app_not_found), Toast.LENGTH_LONG).show(); return true; } PageWidget.this.mediaPlaying = true; PageWidget.this.mediaStartTimeStamp = System.currentTimeMillis() / 1000; PageWidget.super.getActivity().startActivity(intent); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW); Uri data = Uri.parse(url); intent.setData(data); PageWidget.super.getActivity().startActivity(intent); // launch action in mobile browser - not the webview // return true so doesn't follow link within webview return true; } } }); }
From source file:android.support.v7.media.RemotePlaybackClient.java
private boolean doesRouteSupportMessaging() { for (IntentFilter filter : mRoute.getControlFilters()) { if (filter.hasAction(MediaControlIntent.ACTION_SEND_MESSAGE)) { return true; }/*from w w w . j a v a 2 s. c o m*/ } return false; }
From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java
/** * Update IntentFilter of categories and data * @param isInit/* w w w. j a va 2s. c om*/ */ private void updateNonActionIntentFilter(boolean isInit) { // If we don't have any IntentFilter use non-filtering editors if (mAvailbleActions == null) { setFreeFormCategoryEditor(); mDataTextWrapper.setVisibility(View.VISIBLE); mDataTextHeader.setVisibility(View.VISIBLE); mUriAutocompleteAdapter.setIntentFilters(null); setupUnfilteredDataTypeFields(); return; } // Update edited intent if (!isInit) { updateEditedIntent(mEditedIntent); } // Get all IntentFilters final IntentFilter[] allIntentFilters = getIntentEditor().getAttachedIntentFilters(); // Get selected action String action = (String) mActionsSpinner.getSelectedItem(); HashSet<String> availableCategories = new HashSet<String>(); HashSet<String> availableMimeTypes = new HashSet<String>(); boolean acceptsAnyDataType = false; boolean acceptsUntypedData = false; boolean mayAutoDetectType = false; boolean acceptsUris = false; ArrayList<IntentFilter> selectedIntentFilters = new ArrayList<IntentFilter>(); // Iterate over intent filters that has selected action for (IntentFilter filter : allIntentFilters) { if (filter.hasAction(action)) { // List categories if (filter.countCategories() != 0) { for (Iterator<String> iterator = filter.categoriesIterator(); iterator.hasNext();) { availableCategories.add(iterator.next()); } } // List available types or set flag that we don't need them if (filter.countDataTypes() == 0) { acceptsUntypedData = true; } else { for (Iterator<String> iterator = filter.typesIterator(); iterator.hasNext();) { final String type = iterator.next(); if ("*".equals(type)) { acceptsAnyDataType = true; } else { availableMimeTypes.add(type); } } } // Scan schemes to see if system can auto detect type if (!mayAutoDetectType) { if (filter.countDataSchemes() != 0) { for (Iterator<String> iterator = filter.schemesIterator(); iterator.hasNext();) { String scheme = iterator.next(); if ("content".equals(scheme) || "file".equals(scheme)) { mayAutoDetectType = true; break; } } } else if ( // No schemes declared filter.countDataTypes() != 0 && ( // There's at least one !NO_IMPLICIT_URI_ACTIONS.contains(action) || // Action is not on list filter.countDataAuthorities() != 0 // There is host specified )) { // Intent will match empty, content: or file: scheme acceptsUris = true; mayAutoDetectType = true; } } // Check if we have data if (filter.countDataSchemes() != 0) { acceptsUris = true; } // Save used IntentFilter to list because UriAutocompleteAdapter scans them on his own selectedIntentFilters.add(filter); } } // Setup categories setupCategoryCheckBoxes(availableCategories); // Setup data type if (acceptsAnyDataType) { setupUnfilteredDataTypeFields(); } else { setupFilteredDataTypeFields(acceptsUntypedData, mayAutoDetectType, availableMimeTypes); } // Setup data uri mDataTextWrapper.setVisibility(acceptsUris ? View.VISIBLE : View.GONE); mDataTextHeader.setVisibility(acceptsUris ? View.VISIBLE : View.GONE); if (!acceptsUris) { mDataText.setText(""); } mUriAutocompleteAdapter .setIntentFilters(selectedIntentFilters.toArray(new IntentFilter[selectedIntentFilters.size()])); }
From source file:com.linkbubble.Settings.java
public List<ResolveInfo> getAppsThatHandleUrl(String urlAsString, PackageManager packageManager) { List<Intent> browsers = getBrowsers(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(urlAsString)); List<ResolveInfo> infos = packageManager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); ArrayList<ResolveInfo> results = new ArrayList<ResolveInfo>(); for (ResolveInfo info : infos) { IntentFilter filter = info.filter; if (filter != null && filter.hasAction(Intent.ACTION_VIEW)) { // Check if this item is a browser, and if so, ignore it boolean packageOk = true; for (Intent browser : browsers) { if (info.activityInfo.packageName.equals(browser.getComponent().getPackageName())) { packageOk = false;/* w w w . j a va2s .c om*/ break; } } if (packageOk) { // Ensure TapPath is always ignored if (info.activityInfo.packageName.contains("com.digitalashes.tappath")) { //Log.d("blerg", "ignore " + info.activityInfo.packageName); packageOk = false; } else { // And some special case code for me to ignore alternate builds if (BuildConfig.DEBUG) { if (info.activityInfo.packageName.equals("com.linkbubble.playstore") || info.activityInfo.packageName.equals("com.brave.playstore")) { //Log.d("blerg", "ignore " + info.activityInfo.packageName); packageOk = false; } } else { if (info.activityInfo.packageName.equals("com.linkbubble.playstore.dev") || info.activityInfo.packageName.equals("com.brave.playstore.dev")) { //Log.d("blerg", "ignore " + info.activityInfo.packageName); packageOk = false; } } } } if (packageOk) { results.add(info); Log.d("appHandles", info.loadLabel(packageManager) + " for url:" + urlAsString); } } } if (results.size() > 0) { return results; } return null; }
From source file:com.linkbubble.Settings.java
public void updateBrowsers() { if (mBrowsers == null) { mBrowsers = new Vector<Intent>(); mBrowserPackageNames = new ArrayList<String>(); } else {// ww w . j a v a 2 s . c om mBrowsers.clear(); mBrowserPackageNames.clear(); } PackageManager packageManager = mContext.getPackageManager(); Intent queryIntent = new Intent(); queryIntent.setAction(Intent.ACTION_VIEW); queryIntent.setData(Uri.parse("http://www.fdasfjsadfdsfas.com")); // Something stupid that no non-browser app will handle List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(queryIntent, PackageManager.GET_RESOLVED_FILTER); String fallbackDefaultBrowserPackageName = null; String fallbackDefaultBrowserActivityClassName = null; for (ResolveInfo resolveInfo : resolveInfos) { IntentFilter filter = resolveInfo.filter; if (filter != null && filter.hasAction(Intent.ACTION_VIEW) && filter.hasCategory(Intent.CATEGORY_BROWSABLE)) { // Ignore LinkBubble from this list if (resolveInfo.activityInfo.packageName.equals(BuildConfig.APPLICATION_ID)) { mLinkBubbleEntryActivityResolveInfo = resolveInfo; } else if (Util.isValidBrowserPackageName(resolveInfo.activityInfo.packageName)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name); mBrowsers.add(intent); mBrowserPackageNames.add(resolveInfo.activityInfo.packageName); if (resolveInfo.activityInfo.packageName .equals(mContext.getResources().getString(R.string.tab_based_browser_id_name))) { fallbackDefaultBrowserPackageName = resolveInfo.activityInfo.packageName; fallbackDefaultBrowserActivityClassName = resolveInfo.activityInfo.name; } } } } String defaultBrowserPackage = mSharedPreferences.getString(PREFERENCE_DEFAULT_BROWSER_PACKAGE_NAME, null); //String rightConsumeBubblePackageName = mSharedPreferences.getString(PREFERENCE_RIGHT_CONSUME_BUBBLE_PACKAGE_NAME, null); String leftConsumeBubblePackageName = mSharedPreferences .getString(PREFERENCE_LEFT_CONSUME_BUBBLE_PACKAGE_NAME, null); if (fallbackDefaultBrowserPackageName != null) { try { ApplicationInfo applicationInfo = packageManager .getApplicationInfo(fallbackDefaultBrowserPackageName, 0); String defaultBrowserLabel = packageManager.getApplicationLabel(applicationInfo).toString(); if (defaultBrowserPackage == null || !doesPackageExist(packageManager, defaultBrowserPackage)) { SharedPreferences.Editor editor = mSharedPreferences.edit(); editor.putString(PREFERENCE_DEFAULT_BROWSER_LABEL, defaultBrowserLabel); editor.putString(PREFERENCE_DEFAULT_BROWSER_PACKAGE_NAME, fallbackDefaultBrowserPackageName); editor.commit(); } if (leftConsumeBubblePackageName != null && !doesPackageExist(packageManager, leftConsumeBubblePackageName)) { setConsumeBubble(Constant.BubbleAction.ConsumeLeft, Constant.ActionType.View, defaultBrowserLabel, fallbackDefaultBrowserPackageName, fallbackDefaultBrowserActivityClassName); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } }