Getting list of installed app's, easy. But how to launch one of them?

不羁岁月 提交于 2019-12-10 10:54:47

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!