My first application will just be a kind of launcher that I would like to improve. This launcher will launch a custom Home that the user has installed.
That's like the application "Home Switcher, but I would like to do that myself.
So my first goal is to get all "Home" applications list: that's really easy and the code is there:
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
pm=getBaseContext().getPackageManager();
mainIntent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent,0);
Now I would like to do that in a listview. My first problem is to get the Icon: I failed, but that's not my main problem ( if you can help me I would be happy)
I succeed to make a listview with all the names of the installed Home:
for(...){
map = new HashMap<String, String>();
map.put("titre",info.activityInfo.applicationInfo.loadLabel( pm ).toString());
map.put("pck",info.activityInfo.packageName);
listItem.add(map);
}
SimpleAdapter homeAdapter = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.row,
new String[] {"img", "titre"}, new int[] {R.id.img, R.id.titre});
myListView.setAdapter(homeAdapter);
And now when I click on a home, I would like to launch the Home, so what I did is:
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
HashMap<String, String> map = (HashMap<String, String>) myListView.getItemAtPosition(position);
Intent myIntent = new Intent();
myIntent.setPackage(map.get("pck"));
startActivity(myIntent);
}
So, there is a box that that appear and ask me:
Complete action using: LauncherPro - or Sense - or ADW Wallaper Gallery
I think I am close to what I would like to do, but, I think I'm missing something, am I?
Here is a sample project implementing a launcher-style activity.
来源:https://stackoverflow.com/questions/3293253/getting-list-of-installed-apps-easy-but-how-to-launch-one-of-them