If I call
PackageManager pm = getPackageManager () ;
List pis = pm.getInstalledPackages (PackageManager.GET_PROVIDERS) ;
I came across the same issue and found out a better workaround:
public void listAllActivities() throws NameNotFoundException
{
List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
for(PackageInfo pack : packages)
{
ActivityInfo[] activityInfo = getPackageManager().getPackageInfo(pack.packageName, PackageManager.GET_ACTIVITIES).activities;
Log.i("Pranay", pack.packageName + " has total " + ((activityInfo==null)?0:activityInfo.length) + " activities");
if(activityInfo!=null)
{
for(int i=0; i<activityInfo.length; i++)
{
Log.i("PC", pack.packageName + " ::: " + activityInfo[i].name);
}
}
}
}
Notice that I need to query PackageManager
twice. Once using getPackageManager().getInstalledPackages(...)
and again using getPackageManager().getPackageInfo(...)
I hope it helps.