获取系统上可用的所有活动的列表

时间:2011-09-05 10:28:09

标签: android android-activity

由于系统应了解可用的活动,因为它们是在安装期间评估的相应AndroidManifest.xml文件中声明的:
有没有办法查询这些活动?

2 个答案:

答案 0 :(得分:8)

当然,看看PackageManager.getInstalledPackages方法。以下是打印已注册活动名称的示例:

List<PackageInfo> pInfos = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
for (PackageInfo pInfo : pInfos) {
  ActivityInfo[] aInfos = pInfo.activities;
  if (aInfos != null) {
    for (ActivityInfo activityInfo : aInfos) {
      Log.i("ACT", activityInfo.name);
      // do whatever else you like... 
    }
  }
}

答案 1 :(得分:1)

ArrayList<PackageInfo> res = new ArrayList<PackageInfo>();
PackageManager pm = ctx.getPackageManager();
List<PackageInfo> packs = pm.getInstalledPackages(0);

for(int i=0;i<packs.size();i++) {
    PackageInfo p = packs.get(i);
    String description = (String) p.applicationInfo.loadDescription(pm);
    String  label= p.applicationInfo.loadLabel(pm).toString();
    String packageName = p.packageName;
    String versionName = p.versionName;
    String versionCode = p.versionCode;
    String icon = p.applicationInfo.loadIcon(pm);
//Continue to extract other info about the app...
}

注意:将此权限添加到清单文件:

<uses-permission android:name="android.permission.GET_TASKS" />

将此添加到上面的代码:

PackageManager.getactivities -- I have not used this PackageManager.getactivities but I hope it will work for you....