I am trying to load the logo associated with the current activity and/or its parent application from the definition in the manifest. This technique has already worked succes
@Jake Wharton, you are trying to retrieve something that doesn't exist. Unlike applications, activities do not have a separate logo attribute (the logo defined in the application becomes the default attribute for all activities). This is why you are unable to retrieve one from an activity.
From my tests, your code works properly running on a Honeycomb device, but not on a Gingerbread or below device. That seems to imply that the android:logo
functionality, although present in API Level 8, is not implemented correctly in the underlying platform. That is, the same application apk on a Level 8-10 device is not retaining the logo attribute, but a Level 11 device does. That means the problem is not with the code or the AndroidManifest.xml, but with the platform.
If you take a look at the code in android.app.ContextImpl.ApplicationPackageManager
(here), you will find that eventually it uses the method
public Drawable getDrawable(String packageName,int resid,ApplicationInfo appInfo)
(lines 2131 to 2173 in 2.3).
There are several Log.w
calls there that you can use to follow what is going on through adb (i.e., Failure retrieving resources for
...)
First you need to find all the applications that are installed. For this purpose us the following methods from package manager,
public abstract List<PackageInfo> getInstalledPackages (int flags)
more info here
You can also use the following method for getting info on installed packages.
public abstract List<ApplicationInfo> getInstalledApplications (int flags)
more info here
Now after getting the list, iterate it using the following method.
public Drawable getDrawable(String packageName,int resid,ApplicationInfo appInfo)
more info here
Each iteration will give you the respective drawable of the package queried. here res id is the id of the icon..
R.drawable.icon