DonGru
DonGru

Reputation: 13710

Get list of all Activities available on the System

Since the system should know about the available Activities as they are declared in the appropriate AndroidManifest.xml files which are evaluated during installation:
Is there a way to query these Activities?

Upvotes: 3

Views: 6205

Answers (2)

Vineet Shukla
Vineet Shukla

Reputation: 24031

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...
}

Note: Add this permission to the manifest file:

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

Add this to above code:

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

Upvotes: 1

Volo
Volo

Reputation: 29438

Sure, have a look at PackageManager.getInstalledPackages method. Here is the example of printing registered activities names:

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... 
    }
  }
}

Upvotes: 8

Related Questions