Java Code Examples for android.content.pm.PackageManager#resolveActivity()
The following examples show how to use
android.content.pm.PackageManager#resolveActivity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BadgeUtil.java From MissZzzReader with Apache License 2.0 | 6 votes |
/** * Retrieve launcher activity name of the application from the context * * @param context The context of the application package. * @return launcher activity name of this application. From the * "android:name" attribute. */ private static String getLauncherClassName(Context context) { PackageManager packageManager = context.getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN); // To limit the components this Intent will resolve to, by setting an // explicit package name. intent.setPackage(context.getPackageName()); intent.addCategory(Intent.CATEGORY_LAUNCHER); // All Application must have 1 Activity at least. // Launcher activity must be found! ResolveInfo info = packageManager .resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); // get a ResolveInfo containing ACTION_MAIN, CATEGORY_LAUNCHER // if there is no Activity which has filtered by CATEGORY_DEFAULT if (info == null) { info = packageManager.resolveActivity(intent, 0); } return info.activityInfo.name; }
Example 2
Source File: DocumentUtils.java From delion with Apache License 2.0 | 6 votes |
/** * Given an AppTask retrieves the task class name. * @param task The app task to use. * @param pm The package manager to use for resolving intent. * @return Fully qualified class name or null if we were not able to * determine it. */ public static String getTaskClassName(AppTask task, PackageManager pm) { RecentTaskInfo info = getTaskInfoFromTask(task); if (info == null) return null; Intent baseIntent = info.baseIntent; if (baseIntent == null) { return null; } else if (baseIntent.getComponent() != null) { return baseIntent.getComponent().getClassName(); } else { ResolveInfo resolveInfo = pm.resolveActivity(baseIntent, 0); if (resolveInfo == null) return null; return resolveInfo.activityInfo.name; } }
Example 3
Source File: DefaultWebClient.java From AgentWebX5 with Apache License 2.0 | 6 votes |
private void handleIntentUrl(String intentUrl) { try { Intent intent = null; if (TextUtils.isEmpty(intentUrl) || !intentUrl.startsWith(INTENT_SCHEME)) return; Activity mActivity = null; if ((mActivity = mWeakReference.get()) == null) return; PackageManager packageManager = mActivity.getPackageManager(); intent = new Intent().parseUri(intentUrl, Intent.URI_INTENT_SCHEME); ResolveInfo info = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); LogUtils.i("Info", "resolveInfo:" + info + " package:" + intent.getPackage()); if (info != null) { //跳到该应用 mActivity.startActivity(intent); return; } } catch (Exception e) { e.printStackTrace(); } }
Example 4
Source File: AppUtils.java From loco-answers with GNU General Public License v3.0 | 6 votes |
private static String getCurrentLauncherApp(Context context) { String str = ""; PackageManager localPackageManager = context.getPackageManager(); Intent intent = new Intent("android.intent.action.MAIN"); intent.addCategory("android.intent.category.HOME"); try { ResolveInfo resolveInfo = localPackageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfo != null && resolveInfo.activityInfo != null) { str = resolveInfo.activityInfo.packageName; } } catch (Exception e) { Log.e("AppUtils", "Exception : " + e.getMessage()); } return str; }
Example 5
Source File: ActivityUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 判断是否存在指定的 Activity * @param packageName 应用包名 * @param className Activity.class.getCanonicalName() * @return {@code true} 存在, {@code false} 不存在 */ public static boolean isActivityExists(final String packageName, final String className) { if (packageName == null || className == null) return false; boolean result = true; try { PackageManager packageManager = AppUtils.getPackageManager(); Intent intent = new Intent(); intent.setClassName(packageName, className); if (packageManager.resolveActivity(intent, 0) == null) { result = false; } else if (intent.resolveActivity(packageManager) == null) { result = false; } else { List<ResolveInfo> lists = packageManager.queryIntentActivities(intent, 0); if (lists.size() == 0) { result = false; } } } catch (Exception e) { result = false; LogPrintUtils.eTag(TAG, e, "isActivityExists"); } return result; }
Example 6
Source File: BaseActivityLauncher.java From SmartGo with Apache License 2.0 | 5 votes |
private boolean isAvailable(final Context context,final Intent intent){ final PackageManager manager = context.getPackageManager(); final ResolveInfo info = manager.resolveActivity( intent, PackageManager.MATCH_DEFAULT_ONLY); return info != null; }
Example 7
Source File: Intents.java From cathode with Apache License 2.0 | 5 votes |
public static void openUrl(Context context, String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); PackageManager pm = context.getPackageManager(); if (pm.resolveActivity(intent, 0) != null) { context.startActivity(intent); } }
Example 8
Source File: EthereumAndroidFactory.java From ethereum-android-lib with Apache License 2.0 | 5 votes |
public boolean showInstallationDialog() { Intent playIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=de.petendi.ethereum.android")); final PackageManager pm = context.getPackageManager(); if (pm.resolveActivity(playIntent, 0) != null) { context.startActivity(playIntent); return true; } else { return false; } }
Example 9
Source File: NotificationModule.java From things-notification with Apache License 2.0 | 5 votes |
private String getDefaultSmsPackage() { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return Telephony.Sms.getDefaultSmsPackage(reactContext); } else { String defApp = Settings.Secure.getString(reactContext.getContentResolver(), "sms_default_application"); PackageManager pm = reactContext.getApplicationContext().getPackageManager(); Intent iIntent = pm.getLaunchIntentForPackage(defApp); ResolveInfo mInfo = pm.resolveActivity(iIntent,0); return mInfo.activityInfo.packageName; } }
Example 10
Source File: CorrectionSettingsFragment.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
@Override public void onCreate(final Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.prefs_screen_correction); final Context context = getActivity(); final PackageManager pm = context.getPackageManager(); /* * IndicKeyboard: We are not yet supporting dictionary download. final Preference dictionaryLink = findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY); final Intent intent = dictionaryLink.getIntent(); intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName()); final int number = pm.queryIntentActivities(intent, 0).size(); if (0 >= number) { */ if (true) { removePreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY); } final Preference editPersonalDictionary = findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY); final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent(); final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS ? null : pm.resolveActivity( editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY); if (ri == null) { overwriteUserDictionaryPreference(editPersonalDictionary); } mUseContactsPreference = (SwitchPreference) findPreference(Settings.PREF_KEY_USE_CONTACTS_DICT); turnOffUseContactsIfNoPermission(); }
Example 11
Source File: PermissionsTest.java From espresso-samples with Apache License 2.0 | 5 votes |
/** * Uses package manager to find the package name of the device launcher. Usually this package * is "com.android.launcher" but can be different at times. This is a generic solution which * works on all platforms.` */ private String getLauncherPackageName() { // Create launcher Intent final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); // Use PackageManager to get the launcher package name PackageManager pm = InstrumentationRegistry.getContext().getPackageManager(); ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); return resolveInfo.activityInfo.packageName; }
Example 12
Source File: SystemAppsManager.java From island with Apache License 2.0 | 5 votes |
/** @param flags intersection of {@code PackageManager.ComponentInfoFlags} and {@code PackageManager.ResolveInfoFlags}. */ @OwnerUser @ProfileUser public static Set<String> detectCriticalSystemPackages(final PackageManager pm, final int flags) { final Stopwatch stopwatch = Performances.startUptimeStopwatch(); final Set<String> critical_sys_pkgs = new HashSet<>(sCriticalSystemPkgs); // Detect package names for critical intent actions, as an addition to the white-list of well-known ones. for (final Intent intent : sCriticalActivityIntents) { @SuppressLint("WrongConstant") final ResolveInfo info = pm.resolveActivity(intent, MATCH_DEFAULT_ONLY | Hacks.MATCH_ANY_USER_AND_UNINSTALLED); if (info == null || (info.activityInfo.applicationInfo.flags & FLAG_SYSTEM) == 0) continue; final String pkg = info.activityInfo.packageName; Log.i(TAG, "Critical package for " + intent + ": " + pkg); critical_sys_pkgs.add(pkg); } Performances.check(stopwatch, 1, "CriticalActivities"); // Detect package names for critical content providers, as an addition to the white-list of well-known ones. for (final String authority : sCriticalContentAuthorities) { if (authority == null) continue; // Nullable for version-specific authorities final ProviderInfo provider = pm.resolveContentProvider(authority, flags); if (provider == null || (provider.applicationInfo.flags & FLAG_SYSTEM) == 0 || (provider.flags & FLAG_SINGLE_USER) != 0) continue; Log.i(TAG, "Critical package for authority \"" + authority + "\": " + provider.packageName); critical_sys_pkgs.add(provider.packageName); } Performances.check(stopwatch, 1, "CriticalProviders"); return critical_sys_pkgs; }
Example 13
Source File: CustomTabsHelper.java From custom-tabs-client with Apache License 2.0 | 4 votes |
/** * Goes through all apps that handle VIEW intents and have a warmup service. Picks * the one chosen by the user if there is one, otherwise makes a best effort to return a * valid package name. * * This is <strong>not</strong> threadsafe. * * @param context {@link Context} to use for accessing {@link PackageManager}. * @return The package name recommended to use for connecting to custom tabs related components. */ public static String getPackageNameToUse(Context context) { if (sPackageNameToUse != null) return sPackageNameToUse; PackageManager pm = context.getPackageManager(); // Get default VIEW intent handler. Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); String defaultViewHandlerPackageName = null; if (defaultViewHandlerInfo != null) { defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; } // Get all apps that can handle VIEW intents. List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); List<String> packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); if (pm.resolveService(serviceIntent, 0) != null) { packagesSupportingCustomTabs.add(info.activityInfo.packageName); } } // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents // and service calls. if (packagesSupportingCustomTabs.isEmpty()) { sPackageNameToUse = null; } else if (packagesSupportingCustomTabs.size() == 1) { sPackageNameToUse = packagesSupportingCustomTabs.get(0); } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName) && !hasSpecializedHandlerIntents(context, activityIntent) && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) { sPackageNameToUse = defaultViewHandlerPackageName; } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { sPackageNameToUse = STABLE_PACKAGE; } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { sPackageNameToUse = BETA_PACKAGE; } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { sPackageNameToUse = DEV_PACKAGE; } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { sPackageNameToUse = LOCAL_PACKAGE; } return sPackageNameToUse; }
Example 14
Source File: CustomTabsHelper.java From Slide with GNU General Public License v3.0 | 4 votes |
/** * Goes through all apps that handle VIEW intents and have a warmup service. Picks * the one chosen by the user if there is one, otherwise makes a best effort to return a * valid package name. * * This is <strong>not</strong> threadsafe. * * @param context {@link Context} to use for accessing {@link PackageManager}. * @return The package name recommended to use for connecting to custom tabs related components. */ public static String getPackageNameToUse(Context context) { if (SettingValues.linkHandlingMode != LinkHandlingMode.CUSTOM_TABS.getValue()) return null; if (sPackageNameToUse != null) return sPackageNameToUse; PackageManager pm = context.getPackageManager(); // Get default VIEW intent handler. Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); String defaultViewHandlerPackageName = null; if (defaultViewHandlerInfo != null) { defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; } // Get all apps that can handle VIEW intents. List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); List<String> packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); // Samsung browser custom tabs has a bug that harms user experience, pressing back // navigates between pages rather than exiting back to Slide // TODO: Reevaluate at a later date if (pm.resolveService(serviceIntent, 0) != null && !info.activityInfo.packageName.equals("com.sec.android.app.sbrowser")) { packagesSupportingCustomTabs.add(info.activityInfo.packageName); } } // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents // and service calls. if (packagesSupportingCustomTabs.isEmpty()) { sPackageNameToUse = null; } else if (packagesSupportingCustomTabs.size() == 1) { sPackageNameToUse = packagesSupportingCustomTabs.get(0); } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName) && !hasSpecializedHandlerIntents(context, activityIntent) && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) { sPackageNameToUse = defaultViewHandlerPackageName; } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { sPackageNameToUse = STABLE_PACKAGE; } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { sPackageNameToUse = BETA_PACKAGE; } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { sPackageNameToUse = DEV_PACKAGE; } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { sPackageNameToUse = LOCAL_PACKAGE; } return sPackageNameToUse; }
Example 15
Source File: CustomTabsHelper.java From cordova-plugin-safariviewcontroller with MIT License | 4 votes |
public static String getDefaultViewHandlerPackageName(Context context) { PackageManager pm = context.getPackageManager(); // Get default VIEW intent handler. ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); return defaultViewHandlerInfo == null ? null : defaultViewHandlerInfo.activityInfo.packageName; }
Example 16
Source File: CustomTabsHelper.java From rides-android-sdk with MIT License | 4 votes |
/** * Goes through all apps that handle VIEW intents and have a warmup service. Picks * the one chosen by the user if there is one, otherwise makes a best effort to return a * valid package name. * * This is <strong>not</strong> threadsafe. * * @param context {@link Context} to use for accessing {@link PackageManager}. * @return The package name recommended to use for connecting to custom tabs related components. */ @Nullable public String getPackageNameToUse(Context context) { if (packageNameToUse != null) return packageNameToUse; PackageManager pm = context.getPackageManager(); // Get default VIEW intent handler. Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); String defaultViewHandlerPackageName = null; if (defaultViewHandlerInfo != null) { defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; } // Get all apps that can handle VIEW intents. List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); List<String> packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); if (pm.resolveService(serviceIntent, 0) != null) { packagesSupportingCustomTabs.add(info.activityInfo.packageName); } } // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents // and service calls. if (packagesSupportingCustomTabs.isEmpty()) { packageNameToUse = null; } else if (packagesSupportingCustomTabs.size() == 1) { packageNameToUse = packagesSupportingCustomTabs.get(0); } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName) && !hasSpecializedHandlerIntents(context, activityIntent) && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) { packageNameToUse = defaultViewHandlerPackageName; } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { packageNameToUse = STABLE_PACKAGE; } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { packageNameToUse = BETA_PACKAGE; } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { packageNameToUse = DEV_PACKAGE; } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { packageNameToUse = LOCAL_PACKAGE; } return packageNameToUse; }
Example 17
Source File: AllAppsGridAdapter.java From Trebuchet with GNU General Public License v3.0 | 4 votes |
public AllAppsGridAdapter(Launcher launcher, AlphabeticalAppsList apps, View.OnTouchListener touchListener, View.OnClickListener iconClickListener, View.OnLongClickListener iconLongClickListener) { Resources res = launcher.getResources(); mLauncher = launcher; mApps = apps; mEmptySearchMessage = res.getString(R.string.all_apps_loading_message); mGridSizer = new GridSpanSizer(); mGridLayoutMgr = new AppsGridLayoutManager(launcher); mGridLayoutMgr.setSpanSizeLookup(mGridSizer); mItemDecoration = new GridItemDecoration(); mLayoutInflater = LayoutInflater.from(launcher); mTouchListener = touchListener; mIconClickListener = iconClickListener; mIconLongClickListener = iconLongClickListener; mSectionNamesMargin = mSectionStrategy == AllAppsContainerView.SECTION_STRATEGY_GRID ? res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin) : res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections); mAllAppsTextColor = mGridTheme == AllAppsContainerView.GRID_THEME_DARK ? res.getColor(R.color.quantum_panel_text_color_dark) : res.getColor(R.color.quantum_panel_text_color); mSectionHeaderOffset = res.getDimensionPixelSize(R.dimen.all_apps_grid_section_y_offset); mSectionTextPaint = new Paint(); mSectionTextPaint.setTextSize(res.getDimensionPixelSize( R.dimen.all_apps_grid_section_text_size)); int sectionTextColorId = mGridTheme == AllAppsContainerView.GRID_THEME_DARK ? R.color.all_apps_grid_section_text_color_dark : R.color.all_apps_grid_section_text_color; mSectionTextPaint.setColor(res.getColor(sectionTextColorId)); mSectionTextPaint.setAntiAlias(true); mPredictedAppsDividerPaint = new Paint(); mPredictedAppsDividerPaint.setStrokeWidth(Utilities.pxFromDp(1f, res.getDisplayMetrics())); mPredictedAppsDividerPaint.setColor(0x1E000000); mPredictedAppsDividerPaint.setAntiAlias(true); mPredictionBarDividerOffset = res.getDimensionPixelSize(R.dimen.all_apps_prediction_bar_divider_offset); // Resolve the market app handling additional searches PackageManager pm = launcher.getPackageManager(); ResolveInfo marketInfo = pm.resolveActivity(createMarketSearchIntent(""), PackageManager.MATCH_DEFAULT_ONLY); if (marketInfo != null) { mMarketAppName = marketInfo.loadLabel(pm).toString(); } mRemoteFolderManager = launcher.getRemoteFolderManager(); }
Example 18
Source File: CustomTabsHelper.java From mvvm-template with GNU General Public License v3.0 | 4 votes |
/** * Goes through all apps that handle VIEW intents and have a warmup service. Picks * the one chosen by the user if there is one, otherwise makes a best effort to return a * valid package name. * <p> * This is <strong>not</strong> threadsafe. * * @param context * {@link Context} to use for accessing {@link PackageManager}. * @return The package name recommended to use for connecting to custom tabs related components. */ static String getPackageNameToUse(Context context) { if (sPackageNameToUse != null) return sPackageNameToUse; PackageManager pm = context.getPackageManager(); // Get default VIEW intent handler. Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); String defaultViewHandlerPackageName = null; if (defaultViewHandlerInfo != null) { defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; } // Get all apps that can handle VIEW intents. List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); List<String> packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); if (pm.resolveService(serviceIntent, 0) != null) { packagesSupportingCustomTabs.add(info.activityInfo.packageName); } } // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents // and service calls. if (packagesSupportingCustomTabs.isEmpty()) { sPackageNameToUse = null; } else if (packagesSupportingCustomTabs.size() == 1) { sPackageNameToUse = packagesSupportingCustomTabs.get(0); } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName) && !hasSpecializedHandlerIntents(context, activityIntent) && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) { sPackageNameToUse = defaultViewHandlerPackageName; } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { sPackageNameToUse = STABLE_PACKAGE; } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { sPackageNameToUse = BETA_PACKAGE; } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { sPackageNameToUse = DEV_PACKAGE; } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { sPackageNameToUse = LOCAL_PACKAGE; } return sPackageNameToUse; }
Example 19
Source File: CustomTabsHelper.java From AndroidProjects with MIT License | 4 votes |
/** * Goes through all apps that handle VIEW intents and have a warmup service. Picks * the one chosen by the user if there is one, otherwise makes a best effort to return a * valid package name. * * This is <strong>not</strong> threadsafe. * * @param context {@link Context} to use for accessing {@link PackageManager}. * @return The package name recommended to use for connecting to custom tabs related components. */ public static String getPackageNameToUse(Context context) { if (sPackageNameToUse != null) return sPackageNameToUse; PackageManager pm = context.getPackageManager(); // Get default VIEW intent handler. Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); String defaultViewHandlerPackageName = null; if (defaultViewHandlerInfo != null) { defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; } // Get all apps that can handle VIEW intents. List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); List<String> packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); if (pm.resolveService(serviceIntent, 0) != null) { packagesSupportingCustomTabs.add(info.activityInfo.packageName); } } // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents // and service calls. if (packagesSupportingCustomTabs.isEmpty()) { sPackageNameToUse = null; } else if (packagesSupportingCustomTabs.size() == 1) { sPackageNameToUse = packagesSupportingCustomTabs.get(0); } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName) && !hasSpecializedHandlerIntents(context, activityIntent) && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) { sPackageNameToUse = defaultViewHandlerPackageName; } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { sPackageNameToUse = STABLE_PACKAGE; } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { sPackageNameToUse = BETA_PACKAGE; } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { sPackageNameToUse = DEV_PACKAGE; } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { sPackageNameToUse = LOCAL_PACKAGE; } return sPackageNameToUse; }
Example 20
Source File: SettingsActivity.java From Orin with GNU General Public License v3.0 | 4 votes |
private boolean hasEqualizer() { final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); PackageManager pm = getActivity().getPackageManager(); ResolveInfo ri = pm.resolveActivity(effects, 0); return ri != null; }