When using the PackageManager to get a list of applications from the device, if i call pm.getApplicationIcon(app);
and the application does not have an icon, the system will return the system default as it's supposed to do, but i get this error output in my console:
W/ResourceType: No package identifier when getting value for resource number 0x00000000
W/PackageManager: Failure retrieving resources for com.google.android.gsf.login: Resource ID #0x0
Since i'm looping through all applications on the phone, this turns into some pretty bad spam that I'd like to avoid if possible.
My Code
PackageManager pm = getActivity().getApplicationContext().getPackageManager();
for (ApplicationInfo app : pm.getInstalledApplications(0)) {
long dataUsed = ((TrafficStats.getUidRxBytes(app.uid) + TrafficStats.getUidTxBytes(app.uid)) / 1000) / 1000;
if ((int)dataUsed > 0) {
String name = pm.getApplicationLabel(app).toString();
Drawable icon = pm.getApplicationIcon(app);
// Custom object
DataUsageItem item = new DataUsageItem(name, icon, false, dataUsed, new int[]{ 0 , 0 , 0 , 0 , 0 , 0 , 0 });
items.add(item);
}
}
The ApplicationInfo
for each will have an icon
field that holds the resource ID for that drawable in the given package. Check that it's nonzero before calling getApplicationIcon()
.
For those packages that do not have an icon – i.e., those whose icon
field is zero – you can retrieve the system default icon with the android.R.drawable.sym_def_app_icon
ID.