Reputation: 4753
Ok i am using this code to get the list of applications on the phone but how do i display them on screen?
final PackageManager pm = getPackageManager();
List<applicationinfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG,
"Launch Activity :"
+ pm.getLaunchIntentForPackage(packageInfo.packageName));
}
Im trying to display them in a listview but im having a bit of trouble. Could someone please help?
Upvotes: 3
Views: 4537
Reputation: 5183
This might be of some help to you.
public class AppList extends Activity {
private ListView lView;
private ArrayList results = new ArrayList();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lView = (ListView) findViewById(R.id.list1);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}
lView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
}
}
Upvotes: 7
Reputation: 782
You should create an Adapter which implements ListAdapter. As basis you can use the BaseAdapter. For more info you could visit this tutorial
Upvotes: 0