xin287078489
xin心
采纳率100%
2015-10-27 14:00 阅读 3.6k

applicationInfo中如何获取应用程序启动Activity的name

private static void getAppInfo(ApplicationInfo applicationInfo) {
String packageName = applicationInfo.packageName;// 包名
String activityName = applicationInfo.name; // 获得该应用程序的启动Activity的name
String appLabel = (String) applicationInfo.loadLabel(pm); // 获得应用程序的Label
Drawable icon = applicationInfo.loadIcon(pm); // 获得应用程序图标
// 为应用程序的启动Activity 准备Intent
Intent launchIntent = new Intent();
launchIntent.setComponent(new ComponentName(packageName,
activityName));
AppInfo appInfo = new AppInfo();
appInfo.setAppLabel(appLabel);
appInfo.setPkgName(packageName);
appInfo.setAppIcon(icon);
appInfo.setIntent(launchIntent);
mlistAppInfo.add(appInfo);
}这样是获取不到的

     Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    // 通过查询,获得所有ResolveInfo对象.
    List<ResolveInfo> resolveInfos = pm
            .queryIntentActivities(mainIntent, PackageManager.MATCH_DEFAULT_ONLY);
    // 调用系统排序 , 根据name排序
    // 该排序很重要,否则只能显示系统应用,而不能列出第三方应用程序
    Collections.sort(resolveInfos, new ResolveInfo.DisplayNameComparator(pm));
    if (mlistAppInfo != null) {
        mlistAppInfo.clear();
        for (ResolveInfo reInfo : resolveInfos) {
            String activityName = reInfo.activityInfo.name; // 获得该应用程序的启动Activity的name
            String pkgName = reInfo.activityInfo.packageName; // 获得应用程序的包名
            String appLabel = (String) reInfo.loadLabel(pm); // 获得应用程序的Label
            Drawable icon = reInfo.loadIcon(pm); // 获得应用程序图标
            // 为应用程序的启动Activity 准备Intent
            Intent launchIntent = new Intent();
            launchIntent.setComponent(new ComponentName(pkgName,
                    activityName));这样就行
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

相关推荐