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


Java PackageManager.queryIntentActivities方法代码示例

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


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

示例1: hasSpecializedHandlerIntents

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * Used to check whether there is a specialized handler for a given intent.
 * @param intent The intent to check with.
 * @return Whether there is a specialized handler for the given intent.
 */
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
    try {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> handlers = pm.queryIntentActivities(
                intent,
                PackageManager.GET_RESOLVED_FILTER);
        if (handlers == null || handlers.size() == 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : handlers) {
            IntentFilter filter = resolveInfo.filter;
            if (filter == null) continue;
            if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
            if (resolveInfo.activityInfo == null) continue;
            return true;
        }
    } catch (RuntimeException e) {
        Log.e(TAG, "Runtime exception while getting specialized handlers");
    }
    return false;
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:27,代码来源:CustomTabsHelper.java

示例2: openApp

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean openApp(Context context, String isAppPackageName) {
    Intent mainIntent = new Intent("android.intent.action.MAIN", null);
    mainIntent.addCategory("android.intent.category.LAUNCHER");
    PackageManager mPackageManager = BaseApplication.getInstance().getApplicationContext().getPackageManager();
    List<ResolveInfo> mAllApps = mPackageManager.queryIntentActivities(mainIntent, 0);
    Collections.sort(mAllApps, new DisplayNameComparator(mPackageManager));
    for (ResolveInfo res : mAllApps) {
        String pkg = res.activityInfo.packageName;
        String cls = res.activityInfo.name;
        LogInfo.log("Emerson", "-------pkg = " + pkg + "--cls = " + cls);
        if (res.activityInfo.packageName.equals(isAppPackageName)) {
            ComponentName componet = new ComponentName(pkg, cls);
            Intent intent = new Intent();
            intent.setComponent(componet);
            intent.addFlags(268435456);
            context.startActivity(intent);
            return true;
        }
    }
    return false;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:LetvUtils.java

示例3: getAppForShare

import android.content.pm.PackageManager; //导入方法依赖的package包/类
private ActivityInfo getAppForShare(StickerData stickerData) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    //intent.setType("image/gif");
    intent.setType(stickerData.mime);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
    for (ResolveInfo act : activities) {
        ActivityInfo ai = act.activityInfo;
        //Log.d("###",""+editorInfo.packageName+" :: "+ai.applicationInfo.packageName+" | "+ai.name);
        if (editorInfo.packageName.equalsIgnoreCase(ai.applicationInfo.packageName)) {
            return ai;
        }
    }
    return null;
}
 
开发者ID:ROKOLabs,项目名称:ROKOmoji.Emoji.Keyboard.App-Android,代码行数:17,代码来源:KeyboardService.java

示例4: resolveBrowsers

import android.content.pm.PackageManager; //导入方法依赖的package包/类
private Map<String, ActivityInfo> resolveBrowsers(Context context, PackageManager packageManager, @NonNull Uri uri) {
    final Map<String, ActivityInfo> browsers = new HashMap<>();

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

    final List<ResolveInfo> infos = packageManager.queryIntentActivities(intent, 0);

    for (ResolveInfo info : infos) {
        if (!context.getPackageName().equals(info.activityInfo.packageName)) {
            browsers.put(info.activityInfo.packageName, info.activityInfo);
        }
    }

    return browsers;
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:17,代码来源:Browsers.java

示例5: isHaveMarket

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean isHaveMarket(Context context) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_APP_MARKET);
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
    return infos.size() > 0;
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:8,代码来源:TDevice.java

示例6: startWithNoWebUrl

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean startWithNoWebUrl(Uri uri) {
    String path = uri.getPath();
    if (!TextUtils.isEmpty(path)) {
        Intent intent = FileUtils.buildOpenIntent(uri);
        if (intent != null) { //优先通过外部程序打开
            PackageManager packageManager = getContext().getPackageManager();
            List<ResolveInfo> activityInfoList = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL);
            if (activityInfoList != null && activityInfoList.size() > 0) {
                jumpActivity(intent);
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:vsona,项目名称:RxJava2RetrofitDemo,代码行数:16,代码来源:WebUtils.java

示例7: loadShortcuts

import android.content.pm.PackageManager; //导入方法依赖的package包/类
@SuppressLint("WrongConstant")
public static List<ShortcutInfo> loadShortcuts(Context context, String packageName) {
    if (!SDKUtil.AT_LEAST_N_MR1) {
        return null;
    }

    LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
    if (launcherApps == null) {
        return null;
    }

    if (!launcherApps.hasShortcutHostPermission()) {
        return null;
    }

    PackageManager packageManager = context.getPackageManager();
    Intent mainIntent = new Intent("android.intent.action.MAIN", null);
    mainIntent.addCategory("android.intent.category.LAUNCHER");

    if (packageManager != null && packageManager.queryIntentActivities(mainIntent, 0) != null) {
        try {
            return launcherApps.getShortcuts((new LauncherApps.ShortcutQuery())
                            .setPackage(packageName).setQueryFlags(QUERY_FLAGS),
                    UserHandle.getUserHandleForUid(context.getPackageManager().getPackageUid(packageName, PackageManager.GET_META_DATA)));
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();

            return null;
        }
    }

    return null;
}
 
开发者ID:OhMyLob,项目名称:Paper-Launcher,代码行数:34,代码来源:ShortcutsLoader.java

示例8: isHaveMarket

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean isHaveMarket(Context context) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.APP_MARKET");
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
    return infos.size() > 0;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:DeviceUtils.java

示例9: getUninstallAppList

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public ArrayList<AppBean> getUninstallAppList() {
    PackageManager localPackageManager = mContext.getPackageManager();
    Intent localIntent = new Intent("android.intent.action.MAIN");
    localIntent.addCategory("android.intent.category.LAUNCHER");
    List<ResolveInfo> localList = localPackageManager.queryIntentActivities(localIntent, 0);
    ArrayList<AppBean> localArrayList = null;
    Iterator<ResolveInfo> localIterator = null;
    if (localList != null) {
        localArrayList = new ArrayList<AppBean>();
        localIterator = localList.iterator();
    }
    while (true) {
        if (!localIterator.hasNext())
            break;
        ResolveInfo localResolveInfo = (ResolveInfo) localIterator.next();
        AppBean localAppBean = new AppBean();
        localAppBean.setIcon(localResolveInfo.activityInfo.loadIcon(localPackageManager));
        localAppBean.setName(localResolveInfo.activityInfo.loadLabel(localPackageManager).toString());
        localAppBean.setPackageName(localResolveInfo.activityInfo.packageName);
        localAppBean.setDataDir(localResolveInfo.activityInfo.applicationInfo.publicSourceDir);
        String pkgName = localResolveInfo.activityInfo.packageName;
        PackageInfo mPackageInfo;
        try {
            mPackageInfo = mContext.getPackageManager().getPackageInfo(pkgName, 0);
            if ((mPackageInfo.applicationInfo.flags & mPackageInfo.applicationInfo.FLAG_SYSTEM) > 0) {//系统预装
                localAppBean.setSysApp(true);
            } else {
                localArrayList.add(localAppBean);
            }
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }
    return localArrayList;
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:36,代码来源:GetAppList.java

示例10: 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

示例11: isActivityAvailable

import android.content.pm.PackageManager; //导入方法依赖的package包/类
static boolean isActivityAvailable(Context cxt, Intent intent) {
    PackageManager pm = cxt.getPackageManager();
    if (pm == null) {
        return false;
    }
    List<ResolveInfo> list = pm.queryIntentActivities(
            intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list != null && list.size() > 0;
}
 
开发者ID:NicoLiutong,项目名称:miaosou,代码行数:10,代码来源:MiniPayUtils.java

示例12: isVoiceAvailable

import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean isVoiceAvailable() {
    if (isInEditMode()) {
        return true;
    }
    PackageManager pm = getContext().getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    return activities.size() != 0;
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:9,代码来源:SearchView.java

示例13: getActivity

import android.content.pm.PackageManager; //导入方法依赖的package包/类
private ActivityInfo getActivity(final CallbackContext callbackContext, final Intent shareIntent, final String appPackageName, final String appName) {
  final PackageManager pm = webView.getContext().getPackageManager();
  List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
  for (final ResolveInfo app : activityList) {
    if ((app.activityInfo.packageName).contains(appPackageName)) {
      if (appName == null || (app.activityInfo.name).contains(appName)) {
        return app.activityInfo;
      }
    }
  }
  // no matching app found
  callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, getShareActivities(activityList)));
  return null;
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:15,代码来源:SocialSharing.java

示例14: getHomes

import android.content.pm.PackageManager; //导入方法依赖的package包/类
private List<String> getHomes() {
    List<String> names = new ArrayList();
    PackageManager packageManager = getPackageManager();
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.HOME");
    for (ResolveInfo ri : packageManager.queryIntentActivities(intent, 65536)) {
        names.add(ri.activityInfo.packageName);
    }
    return names;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:11,代码来源:DialogService.java

示例15: getData

import android.content.pm.PackageManager; //导入方法依赖的package包/类
protected List<Map<String, Object>> getData(String prefix) {
    List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>();

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(APP_CAGEGORY);

    PackageManager pm = getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);

    if (null == list)
        return myData;

    String[] prefixPath;
    String prefixWithSlash = prefix;

    if (prefix.equals("")) {
        prefixPath = null;
    } else {
        prefixPath = prefix.split("/");
        prefixWithSlash = prefix + "/";
    }

    int len = list.size();

    Map<String, Boolean> entries = new HashMap<String, Boolean>();

    for (int i = 0; i < len; i++) {
        ResolveInfo info = list.get(i);
        CharSequence labelSeq = info.loadLabel(pm);
        String label = labelSeq != null
                ? labelSeq.toString()
                : info.activityInfo.name;

        Log.w("yjt","labelSeq = "+labelSeq+"; label="+label+" ; prefixPath="+prefixPath+" ; prefixWithSlash="+prefixWithSlash);
        if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {

            String[] labelPath = label.split("/");

            String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];

            if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
                addItem(myData, nextLabel, activityIntent(
                        info.activityInfo.applicationInfo.packageName,
                        info.activityInfo.name));
            } else {
                if (entries.get(nextLabel) == null) {
                    addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
                    entries.put(nextLabel, true);
                }
            }
        }
    }

    Collections.sort(myData, sDisplayNameComparator);

    return myData;
}
 
开发者ID:yangjiantao,项目名称:AndroidUiKit,代码行数:58,代码来源:HomeActivity.java


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