List of usage examples for android.content IntentFilter hasCategory
public final boolean hasCategory(String category)
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));//from w ww . j a v a2s. c o m 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 ww w.java2 s . c o m*/ } } return null; }
From source file:com.linkbubble.Settings.java
public void updateBrowsers() { if (mBrowsers == null) { mBrowsers = new Vector<Intent>(); mBrowserPackageNames = new ArrayList<String>(); } else {/*from w w w. j a va2s . c o m*/ 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(); } } }