Java Code Examples for android.content.pm.PackageManager#resolveService()
The following examples show how to use
android.content.pm.PackageManager#resolveService() .
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: CustomTabsDelegate.java From materialistic with Apache License 2.0 | 6 votes |
/** * Returns all browsers that support custom tabs * * @param context Context * @return List of all Packages with custom Tabs support */ private static List<String> getBrowsersWithCustomTabsSupport(Context context) { List<String> packagesSupportingCustomTabs = new ArrayList<>(); PackageManager pm = context.getPackageManager(); List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities( new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")), 0); //noinspection Convert2streamapi for (ResolveInfo info : resolvedActivityList) { if (pm.resolveService(new Intent() .setAction(ACTION_CUSTOM_TABS_CONNECTION) .setPackage(info.activityInfo.packageName), 0) != null) { packagesSupportingCustomTabs.add(info.activityInfo.packageName); } } return packagesSupportingCustomTabs; }
Example 2
Source File: Helper.java From FairEmail with GNU General Public License v3.0 | 6 votes |
static boolean hasCustomTabs(Context context, Uri uri) { String scheme = (uri == null ? null : uri.getScheme()); if (!"http".equals(scheme) && !"https".equals(scheme)) return false; PackageManager pm = context.getPackageManager(); Intent view = new Intent(Intent.ACTION_VIEW, uri); List<ResolveInfo> ris = pm.queryIntentActivities(view, 0); // action whitelisted for (ResolveInfo info : ris) { Intent intent = new Intent(); intent.setAction(ACTION_CUSTOM_TABS_CONNECTION); intent.setPackage(info.activityInfo.packageName); if (pm.resolveService(intent, 0) != null) return true; } return false; }
Example 3
Source File: LinkResolverActivity.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 6 votes |
private ArrayList<ResolveInfo> getCustomTabsPackages(PackageManager pm) { // Get default VIEW intent handler. Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.example.com")); // Get all apps that can handle VIEW intents. List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); ArrayList<ResolveInfo> packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); // Check if this package also resolves the Custom Tabs service. if (pm.resolveService(serviceIntent, 0) != null) { packagesSupportingCustomTabs.add(info); } } return packagesSupportingCustomTabs; }
Example 4
Source File: CustomTabsHelper.java From cordova-plugin-safariviewcontroller with MIT License | 5 votes |
public static List<String> getPackagesSupportingCustomTabs(Context context) { PackageManager pm = context.getPackageManager(); List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, PackageManager.MATCH_ALL); 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); } } return packagesSupportingCustomTabs; }
Example 5
Source File: CustomTabsController.java From Auth0.Android with MIT License | 5 votes |
/** * Query the OS for a Custom Tab compatible Browser application. * It will pick the default browser first if is Custom Tab compatible, then any Chrome browser or the first Custom Tab compatible browser. * * @param context a valid Context * @return the recommended Browser application package name, compatible with Custom Tabs. Null if no compatible browser is found. */ @Nullable static String getBestBrowserPackage(@NonNull Context context) { PackageManager pm = context.getPackageManager(); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); ResolveInfo webHandler = pm.resolveActivity(browserIntent, Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PackageManager.MATCH_ALL : PackageManager.MATCH_DEFAULT_ONLY); String defaultBrowser = null; if (webHandler != null) { defaultBrowser = webHandler.activityInfo.packageName; } List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(browserIntent, 0); List<String> customTabsBrowsers = 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) { customTabsBrowsers.add(info.activityInfo.packageName); } } if (customTabsBrowsers.contains(defaultBrowser)) { return defaultBrowser; } else if (customTabsBrowsers.contains(CHROME_STABLE)) { return CHROME_STABLE; } else if (customTabsBrowsers.contains(CHROME_SYSTEM)) { return CHROME_SYSTEM; } else if (customTabsBrowsers.contains(CHROME_BETA)) { return CHROME_BETA; } else if (customTabsBrowsers.contains(CHROME_DEV)) { return CHROME_DEV; } else if (!customTabsBrowsers.isEmpty()) { return customTabsBrowsers.get(0); } else { return null; } }
Example 6
Source File: CustomTabsHelper.java From Telegram-FOSS with GNU General Public License v2.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; } try { if ("com.sec.android.app.sbrowser".equalsIgnoreCase(sPackageNameToUse)) { pm = ApplicationLoader.applicationContext.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo("com.android.chrome", 0); if (applicationInfo != null && applicationInfo.enabled) { PackageInfo packageInfo = pm.getPackageInfo("com.android.chrome", PackageManager.GET_ACTIVITIES); sPackageNameToUse = "com.android.chrome"; } } } catch (Throwable ignore) { } return sPackageNameToUse; }
Example 7
Source File: CustomTabsHelper.java From android-proguards 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(CustomTabsService.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 8
Source File: CustomTabsHelper.java From MaterialHome 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(CustomTabsService.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 9
Source File: TabsHelper.java From Ruisi 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 10
Source File: BrowserTab.java From cordova-plugin-browsertab with Apache License 2.0 | 4 votes |
private boolean hasCustomTabWarmupService(PackageManager pm, String packageName) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(packageName); return (pm.resolveService(serviceIntent, 0) != null); }
Example 11
Source File: BrowserSelector.java From AppAuth-Android with Apache License 2.0 | 4 votes |
private static boolean hasWarmupService(PackageManager pm, String packageName) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(packageName); return (pm.resolveService(serviceIntent, 0) != null); }
Example 12
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 13
Source File: CustomTabsHelper.java From Telegram with GNU General Public License v2.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; } try { if ("com.sec.android.app.sbrowser".equalsIgnoreCase(sPackageNameToUse)) { pm = ApplicationLoader.applicationContext.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo("com.android.chrome", 0); if (applicationInfo != null && applicationInfo.enabled) { PackageInfo packageInfo = pm.getPackageInfo("com.android.chrome", PackageManager.GET_ACTIVITIES); sPackageNameToUse = "com.android.chrome"; } } } catch (Throwable ignore) { } return sPackageNameToUse; }
Example 14
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 15
Source File: ChromePackageHelper.java From ForceDoze with GNU General Public License v3.0 | 4 votes |
public static String getPackageNameToUse(Context context) { if (sPackageNameToUse != null) return sPackageNameToUse; PackageManager pm = context.getPackageManager(); 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(CustomTabsService.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 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: ChromeCustomTabsHelper.java From Hews 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. * <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. */ 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(CustomTabsService.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 18
Source File: OverlayServiceCommon.java From heads-up with GNU General Public License v3.0 | 4 votes |
private void doFinish(final int doDismiss) { // 0=ikke fjern 1=fjern 2=åpnet Mlog.v(logTag + "DoFinish", doDismiss); handler.removeCallbacks(closeTimer); // Integrate with Voiceify if (doDismiss == 1 || doDismiss == 2) { PackageManager packageManager = getPackageManager(); Intent intent = new Intent("codes.simen.notificationspeaker.STOP_READING"); intent.putExtra("packageName", packageName); intent.putExtra("tag", tag); intent.putExtra("id", id); intent.setPackage("codes.simen.notificationspeaker"); try { ResolveInfo resolveInfo= packageManager.resolveService(intent, 0); if (resolveInfo.serviceInfo != null) { Mlog.d(logTag, "Voiceify found and resolved"); startService(intent); } } catch (NullPointerException ignored) {} // Don't panic! We'll survive without Voiceify } if (Build.VERSION.SDK_INT >= 12) { try { View self = layout.findViewById(R.id.notificationbg); ViewPropertyAnimator animator = self.animate() .setDuration(300) .alpha(0.0f) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { layout.setVisibility(View.GONE); if (doDismiss == 1) doDismiss(true); else if (doDismiss == 2) doDismiss(false); else { if (wLock != null && wLock.isHeld()) wLock.release(); stopSelf(); } } }); if (doDismiss == 1) animator.translationX(-400); else if (doDismiss == 0) switch (position) { case 2: case 1: animator.translationY(-300); break; case -1: animator.translationY(300); break; } } catch (Exception e) { reportError(e, "", getApplicationContext()); e.printStackTrace(); layout.setVisibility(View.GONE); if (doDismiss == 1) doDismiss(true); else if (doDismiss == 2) doDismiss(false); else { if (wLock != null && wLock.isHeld()) wLock.release(); stopSelf(); } } } else { layout.setVisibility(View.GONE); if (doDismiss == 1) doDismiss(true); else if (doDismiss == 2) doDismiss(false); else { if (wLock != null && wLock.isHeld()) wLock.release(); stopSelf(); } } prevPackageName = "0"; }
Example 19
Source File: CustomTabsHelper.java From TelePlus-Android with GNU General Public License v2.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; } try { if ("com.sec.android.app.sbrowser".equalsIgnoreCase(sPackageNameToUse)) { pm = ApplicationLoader.applicationContext.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo("com.android.chrome", 0); if (applicationInfo != null && applicationInfo.enabled) { PackageInfo packageInfo = pm.getPackageInfo("com.android.chrome", PackageManager.GET_ACTIVITIES); sPackageNameToUse = "com.android.chrome"; } } } catch (Throwable ignore) { } return sPackageNameToUse; }
Example 20
Source File: ChromeTabsDelegate.java From SteamGifts with MIT License | 4 votes |
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(CustomTabsService.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 (!android.text.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; } return sPackageNameToUse; }