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