androidandroid-activitynullpackage-managerspackage-info

ActivityInfo[] is null for PackageManager.getInstalledPackages()


Trying to retrieve all activities for each package results in null ActivityInfo array for all of them:

List<PackageInfo> packageInfos = mPackageManager.getInstalledPackages(
                PackageManager.GET_ACTIVITIES &
                PackageManager.GET_SERVICES &
                PackageManager.GET_RECEIVERS &
                PackageManager.GET_PROVIDERS &
                PackageManager.GET_PERMISSIONS);

for (PackageInfo p : packageInfos) 
    Log.wtf(TAG, p.packageName + ": " + (p.activities == null ? "null" :"not null"));

p.activities for all packages is null. According to https://developer.android.com/reference/android/content/pm/PackageInfo.html#activities it shouldn´t be null because GET_ACTIVITIES flag is set.

Where is the problem then?


Solution

  • My bad, I messed with the bitwise operators. Must have used OR operator (|) instead the AND one (&), like this:

    List<PackageInfo> packageInfos = mPackageManager.getInstalledPackages(
                    PackageManager.GET_ACTIVITIES |
                    PackageManager.GET_SERVICES |
                    PackageManager.GET_RECEIVERS |
                    PackageManager.GET_PROVIDERS |
                    PackageManager.GET_PERMISSIONS);
    

    However, this call results in a TransactionTooLargeException because of size limit of data changed between different processes in Android, so most probaly returned packageInfos list will be null or empty