简体   繁体   English

刚安装的应用程序列表

[英]List of just installed apps

I need to store all the installed apps icons in an array, and names in another array, so I´ve this code: 我需要将所有已安装的应用程序图标存储在一个数组中,并将名称存储在另一个数组中,所以我有以下代码:

List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
        int numberApps = apps.size();
        String[] appsNames = new String[numberApps];
        Drawable[] appsIcons = new Drawable[numberApps];


        for(int i=0;i<apps.size();i++) {
            PackageInfo p = apps.get(i);
            String pname = p.packageName;
            String appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
            appsNames[i] = appname;
            Drawable appicon = p.applicationInfo.loadIcon(getPackageManager());
            appsIcons[i] = appicon;

        }

And it works, the problem is that all the apps are displayed, even the system ones, so now i need to change the code for getting just the ones installed or updated by the user. 而且它的工作原理是,所有的应用程序都被显示,甚至是系统的应用程序,因此现在我需要更改代码以仅由用户安装或更新这些应用程序。 I´ve been searching and I´ve found this and this , but as i´m using a Drawable and string array, and I cannot change that, I don´t know how to make it work. 从来就一直在寻找和发现从来就这个这个 ,而是使用可绘制和字符串数组i'm,我不能改变的,我不知道如何使它发挥作用。 Can someone help me please?? 有人能帮助我吗??

I made a overkill solution for my university some weeks ago: you can have a look at this class on Github. 几周前,我为我的大学提出了一个过大的解决方案:您可以在Github上上这堂课

We were dealing with Android Security Flow, so I do not think it is trivial to get what the app is about but the class suits perfectly your needs. 我们正在处理Android Security Flow,所以我认为了解应用程序的内容并不是一件容易的事,但是该类完全可以满足您的需求。

You would need to invest a bit of time to bind it to your app because it is designed to be asynchronous but it would work. 您需要花费一些时间将其绑定到您的应用程序,因为它被设计为异步的,但是可以正常工作。 There are probably simpler options though (but who likes it when it's too simple?) 虽然可能有一些更简单的选项(但是当它太简单时谁会喜欢呢?)

The options you found would work but why are you stuck to an array, can't you create an adapter of it?? 您找到的选项可以使用,但是为什么要固定在阵列上,不能为其创建适配器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM