Reputation: 1969
Well I'm trying to make a ListView
with images and text. I have been following this example: Android: Custom ListView with Image and Text using ArrayAdapter BUT I want the list to be about installed apps and its icons. I have been following this other example to get the icons: Get installed Applications with Name, Package Name, Version and Icon
I have been able to make the list, with icons, but can't get them from installed apps. If I use any pic from my drawable the code works perfectly. So the question is how can I get the icons and add them to my ListView
?
The code is a little bit big, I will try to make it smaller and post it later. Thanks
Upvotes: 0
Views: 302
Reputation: 1969
Well while trying to make it easy to read and post it here I found the solution. This is the magic code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.apps_list_view);
rowItems = new ArrayList<AppListRowItem>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(PackageManager.GET_META_DATA);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
Pinfo newInfo = new Pinfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
PackageNames = p.packageName;
AppNames = p.applicationInfo.loadLabel(getPackageManager()).toString();
test = p.applicationInfo.loadIcon(getPackageManager());
AppListRowItem item = new AppListRowItem(test, AppNames, PackageNames);
rowItems.add(item);
}
Everything else is just like the links posted above.
Upvotes: 1