Java Code Examples for android.content.pm.PackageManager.resolveActivity()

The following are Jave code examples for showing how to use resolveActivity() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: okwallet   File: BitcoinIntegration.java   View Source Code Vote up 6 votes
private static void redirectToDownload(final Context context) {
    Toast.makeText(context, "No Bitcoin application found.\nPlease install Bitcoin Wallet.", Toast.LENGTH_LONG)
            .show();

    final Intent marketIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=com.okwallet"));
    final Intent binaryIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("https://github.com/bitcoin-wallet/bitcoin-wallet/releases"));

    final PackageManager pm = context.getPackageManager();
    if (pm.resolveActivity(marketIntent, 0) != null)
        context.startActivity(marketIntent);
    else if (pm.resolveActivity(binaryIntent, 0) != null)
        context.startActivity(binaryIntent);
    // else out of luck
}
 
Example 2
Project: SimpleUILauncher   File: InstallShortcutReceiver.java   View Source Code Vote up 6 votes
/**
 * Tries to create a new PendingInstallShortcutInfo which represents the same target,
 * but is an app target and not a shortcut.
 * @return the newly created info or the original one.
 */
private static PendingInstallShortcutInfo convertToLauncherActivityIfPossible(
        PendingInstallShortcutInfo original) {
    if (original.isLauncherActivity()) {
        // Already an activity target
        return original;
    }
    if (!Utilities.isLauncherAppTarget(original.launchIntent)
            || !original.user.equals(UserHandleCompat.myUserHandle())) {
        // We can only convert shortcuts which point to a main activity in the current user.
        return original;
    }

    PackageManager pm = original.mContext.getPackageManager();
    ResolveInfo info = pm.resolveActivity(original.launchIntent, 0);

    if (info == null) {
        return original;
    }

    // Ignore any conflicts in the label name, as that can change based on locale.
    LauncherActivityInfoCompat launcherInfo = LauncherActivityInfoCompat
            .fromResolveInfo(info, original.mContext);
    return new PendingInstallShortcutInfo(launcherInfo, original.mContext);
}
 
Example 3
Project: AgentWeb   File: DefaultWebClient.java   View Source Code Vote up 6 votes
private boolean openOtherPage(String intentUrl) {
    try {
        Intent intent;
        Activity mActivity = null;
        if ((mActivity = mWeakReference.get()) == null)
            return true;
        PackageManager packageManager = mActivity.getPackageManager();
        intent = new Intent().parseUri(intentUrl, Intent.URI_INTENT_SCHEME);
        ResolveInfo info = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
        LogUtils.i(TAG, "resolveInfo:" + info + "   package:" + intent.getPackage());
        if (info != null) {  //跳到该应用
            mActivity.startActivity(intent);
            return true;
        }
    } catch (Throwable ignore) {
        if (LogUtils.isDebug()) {
            ignore.printStackTrace();
        }
    }

    return false;
}
 
Example 4
Project: boohee_v5.6   File: SinaSsoHandler.java   View Source Code Vote up 6 votes
private boolean validateAppSignatureForIntent(Context context, Intent intent) {
    PackageManager pm = context.getPackageManager();
    ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
    if (resolveInfo == null) {
        return false;
    }
    try {
        for (Signature signature : pm.getPackageInfo(resolveInfo.activityInfo.packageName,
                64).signatures) {
            if (WEIBO_SIGNATURE.equals(signature.toCharsString())) {
                return true;
            }
        }
        return false;
    } catch (NameNotFoundException e) {
        return false;
    }
}
 
Example 5
Project: FlickLauncher   File: InstallShortcutReceiver.java   View Source Code Vote up 6 votes
/**
 * Tries to create a new PendingInstallShortcutInfo which represents the same target,
 * but is an app target and not a shortcut.
 * @return the newly created info or the original one.
 */
private static PendingInstallShortcutInfo convertToLauncherActivityIfPossible(
        PendingInstallShortcutInfo original) {
    if (original.isLauncherActivity()) {
        // Already an activity target
        return original;
    }
    if (!Utilities.isLauncherAppTarget(original.launchIntent)
            || !original.user.equals(UserHandleCompat.myUserHandle())) {
        // We can only convert shortcuts which point to a main activity in the current user.
        return original;
    }

    PackageManager pm = original.mContext.getPackageManager();
    ResolveInfo info = pm.resolveActivity(original.launchIntent, 0);

    if (info == null) {
        return original;
    }

    // Ignore any conflicts in the label name, as that can change based on locale.
    LauncherActivityInfoCompat launcherInfo = LauncherActivityInfoCompat
            .fromResolveInfo(info, original.mContext);
    return new PendingInstallShortcutInfo(launcherInfo, original.mContext);
}
 
Example 6
Project: LJFramework   File: ActivityUtils.java   View Source Code Vote up 6 votes
/**
 * 判断是否存在Activity
 *
 * @param packageName 包名
 * @param className activity全路径类名
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isActivityExists(String packageName, String className) {
    Intent intent = new Intent();
    intent.setClassName(packageName, className);
    PackageManager packageManager = ContextUtils.getContext()
                                                .getPackageManager();
    return !(packageManager.resolveActivity(intent, 0) == null ||
                     intent.resolveActivity(packageManager) == null ||
                     packageManager.queryIntentActivities(intent, 0)
                                   .isEmpty());
}
 
Example 7
Project: ThunderMusic   File: MediaLockscreenActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onLongClick(View arg0) {
    // 

    if (mSettings.getBoolean("use_as_lock_main", false)) {
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    }
    Intent i = new Intent(
            MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager pm = getPackageManager();

    final ResolveInfo mInfo = pm.resolveActivity(i, 0);

    Intent intent = new Intent();
    intent.setComponent(new ComponentName(
            mInfo.activityInfo.packageName, mInfo.activityInfo.name));
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    startActivity(intent);
    return true;
}
 
Example 8
Project: firefox-tv   File: Browsers.java   View Source Code Vote up 5 votes
private void findKnownBrowsers(PackageManager packageManager, Map<String, ActivityInfo> browsers, @NonNull Uri uri) {
    for (final KnownBrowser browser : KnownBrowser.values()) {
        if (browsers.containsKey(browser.packageName)) {
            continue;
        }

        // resolveActivity() can be slow if the package isn't installed (e.g. 200ms on an N6 with a bad WiFi connection).
        // Hence we query if the package is installed first, and only call resolveActivity for installed packages.
        // getPackageInfo() is fast regardless of a package being installed
        try {
            // We don't need the result, we only need to detect when the package doesn't exist
            packageManager.getPackageInfo(browser.packageName, 0);
        } catch (PackageManager.NameNotFoundException e) {
            continue;
        }

        final Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(uri);
        intent.setPackage(browser.packageName);

        final ResolveInfo info = packageManager.resolveActivity(intent, 0);
        if (info == null || info.activityInfo == null) {
            continue;
        }

        if (!info.activityInfo.exported) {
            continue;
        }

        browsers.put(info.activityInfo.packageName, info.activityInfo);
    }
}
 
Example 9
Project: CSipSimple   File: PhoneCapabilityTester.java   View Source Code Vote up 5 votes
private static void initialize(Context context) {
    final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    
    sIsPhone = (telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE);
    //sIsSipPhone = sIsPhone && SipManager.isVoipSupported(context);
    Intent pIntent = getPriviledgedIntent("123");
    callIntents = getPossibleActivities(context, pIntent);
    PackageManager pm = context.getPackageManager();
    defaultCallIntent = pm.resolveActivity(pIntent, PackageManager.MATCH_DEFAULT_ONLY);
    
    sIsInitialized = true;
}
 
Example 10
Project: AOSP-Kayboard-7.1.2   File: CorrectionSettingsFragment.java   View Source Code Vote up 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();

    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) {
        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
Project: PlusGram   File: CustomTabsHelper.java   View Source Code Vote up 5 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 12
Project: AutoScrollr   File: ChromePackageHelper.java   View Source Code Vote up 5 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 13
Project: GxIconDIY   File: PkgUtil.java   View Source Code Vote up 5 votes
/**
 * Get Activity icon
 */
public static Drawable getIcon(PackageManager pkgManager, String pkgName, String activity) {
    if (pkgManager  == null || TextUtils.isEmpty(pkgName) || TextUtils.isEmpty(activity)) {
        return null;
    }

    Intent intent = new Intent();
    intent.setClassName(pkgName, activity);
    ResolveInfo resolveInfo = pkgManager.resolveActivity(intent, 0);
    if (resolveInfo != null) {
        return resolveInfo.loadIcon(pkgManager);
    }
    return null;
}
 
Example 14
Project: NanoIconPack   File: PkgUtil.java   View Source Code Vote up 5 votes
/**
 * Get Activity icon
 */
public static Drawable getIcon(PackageManager pkgManager, String pkgName, String activity) {
    if (pkgManager  == null || TextUtils.isEmpty(pkgName) || TextUtils.isEmpty(activity)) {
        return null;
    }

    Intent intent = new Intent();
    intent.setClassName(pkgName, activity);
    ResolveInfo resolveInfo = pkgManager.resolveActivity(intent, 0);
    if (resolveInfo != null) {
        return resolveInfo.loadIcon(pkgManager);
    }
    return null;
}
 
Example 15
Project: GitHub   File: CustomTabsHelper.java   View Source Code Vote up 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 16
Project: Tusky   File: CustomTabsHelper.java   View Source Code Vote up 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 17
Project: Orin   File: SettingsActivity.java   View Source Code Vote up 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;
}
 
Example 18
Project: Hello-Music-droid   File: TimberUtils.java   View Source Code Vote up 4 votes
public static boolean hasEffectsPanel(final Activity activity) {
    final PackageManager packageManager = activity.getPackageManager();
    return packageManager.resolveActivity(createEffectsIntent(),
            PackageManager.MATCH_DEFAULT_ONLY) != null;
}
 
Example 19
Project: garras   File: CustomTabsHelper.java   View Source Code Vote up 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
Project: ModuleFrame   File: AppUtil.java   View Source Code Vote up 3 votes
/**
 * 判断App是否安装
 *
 * @param context 上下文
 * @param action   action
 * @param category category
 * @return {@code true}: 已安装<br>{@code false}: 未安装
 */
public static boolean isInstallApp(Context context, final String action, final String category) {
    Intent intent = new Intent(action);
    intent.addCategory(category);
    PackageManager pm = context.getPackageManager();
    ResolveInfo info = pm.resolveActivity(intent, 0);
    return info != null;
}