Android - 列出列表中的应用程序图标并运行选定的

发布于 2024-11-18 15:04:28 字数 990 浏览 4 评论 0原文

我正在 eclipse 中开发 Android 应用程序。

我有一个显示已安装应用程序的列表,列表如下:

            //Listar apps instaladas
        final ListView list1 = (ListView) findViewById(R.id.list1);
        ArrayList results = new ArrayList();
        PackageManager pm = this.getPackageManager();
        Intent inte = new Intent(Intent.ACTION_MAIN, null);
        inte.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> list = pm.queryIntentActivities(inte, PackageManager.PERMISSION_GRANTED);
        for (ResolveInfo rInfo : list) {
            results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
        }
          list1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));

我的问题是: 我怎样才能做到这一点而不是显示图标名称?如果我这样做,

results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());

它会显示“android.graphics.drawable @应用程序的名称” 我该如何通过单击列表来运行应用程序?我尝试了几次,但应用程序出错了。 谢谢!

Im developing an Android app in eclipse.

I have a list showing the applications installed, the list is this:

            //Listar apps instaladas
        final ListView list1 = (ListView) findViewById(R.id.list1);
        ArrayList results = new ArrayList();
        PackageManager pm = this.getPackageManager();
        Intent inte = new Intent(Intent.ACTION_MAIN, null);
        inte.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> list = pm.queryIntentActivities(inte, PackageManager.PERMISSION_GRANTED);
        for (ResolveInfo rInfo : list) {
            results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
        }
          list1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));

My questions are:
How I can do that instead of showing the icons name? if I do it

results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());

show me "android.graphics.drawable @ name of the application"
And how I can do to run the application by clicking on the list? I tried several attempts, but I make the application error.
Thanks!

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

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

发布评论

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

评论(1

恏ㄋ傷疤忘ㄋ疼 2024-11-25 15:04:28

结果.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
通过这行代码,我假设您正在加载应用程序的标签,所以也许您应该尝试 loadName 或其他东西,检查您可以在那里选择什么,因为我自己以前没有这样做过。

当你点击列表时你会得到什么错误?这也会有帮助:)

results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
with this line of code I assume you're loading the label of the application, so perhaps you should try loadName or something, check what you can pick there anyway since I haven't done this myself before.

And which error do you get when you click the list? this would be helpful too :)

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