获取已安装应用程序的列表,很简单。但如何启动其中之一呢?

发布于 2024-09-10 19:57:16 字数 1467 浏览 3 评论 0原文

我的第一个应用程序只是一种我想改进的启动器。 该启动器将启动用户已安装的自定义主页。

这就像应用程序“Home Switcher”,但我想自己做。

所以我的第一个目标是获取所有“Home”应用程序列表:这非常简单,代码就在那里:

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
pm=getBaseContext().getPackageManager();
mainIntent.addCategory(Intent.CATEGORY_HOME); 
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent,0);

现在我想在列表视图中执行此操作我的第一个问题是获取图标:我失败了​​,但这不是我的主要问题(如果你能帮助我,我会很高兴)

我成功地创建了一个包含已安装主页的所有名称的列表视图:

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);

现在当我单击时。在家里,我想启动主页,所以我所做的是:

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);  

}

所以,出现一个框并询问我:

使用以下命令完成操作: LauncherPro - 或 Sense - 或 ADW Wallaper Gallery

我想我已经接近我想做的事情了,但是,我想我错过了一些东西,不是吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文