当前位置: 首页>>代码示例>>Java>>正文


Java PackageManager.resolveService方法代码示例

本文整理汇总了Java中android.content.pm.PackageManager.resolveService方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.resolveService方法的具体用法?Java PackageManager.resolveService怎么用?Java PackageManager.resolveService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.pm.PackageManager的用法示例。


在下文中一共展示了PackageManager.resolveService方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPackageNameToUse

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:57,代码来源:CustomTabsHelper.java

示例2: getPackageNameToUse

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:56,代码来源:CustomTabsHelper.java

示例3: getPackageNameToUse

import android.content.pm.PackageManager; //导入方法依赖的package包/类
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;
}
 
开发者ID:theblixguy,项目名称:AutoScrollr,代码行数:46,代码来源:ChromePackageHelper.java

示例4: getPackageNameToUse

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:56,代码来源:CustomTabsHelper.java

示例5: getPackageNameToUse

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * 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(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;
}
 
开发者ID:tomoya92,项目名称:android-apps,代码行数:56,代码来源:CustomTabsHelper.java

示例6: getPackageNameToUse

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * 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.customtabs) 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;
}
 
开发者ID:ccrama,项目名称:Slide-RSS,代码行数:61,代码来源:CustomTabsHelper.java

示例7: getPackageNameToUse

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * 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(final 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(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()) {
        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;
}
 
开发者ID:saschpe,项目名称:android-customtabs,代码行数:58,代码来源:CustomTabsPackageHelper.java


注:本文中的android.content.pm.PackageManager.resolveService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。