首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Kotlin获取Android应用程序列表

使用Kotlin获取Android应用程序列表
EN

Stack Overflow用户
提问于 2020-10-04 04:31:23
回答 1查看 294关注 0票数 1

我在IntelliJ中使用Kotlin,是的,我已经在Java上尝试过了,结果更糟糕。只给了我3个应用程序: Google、Go Time(目前正在运行的应用程序)和Play Store。

我正试图在我的设备上获得一个完整的应用程序列表。当我尝试使用意图过滤器,我只是得到三个应用提到斜体字。下面是我使用的函数:

代码语言:javascript
运行
复制
    private fun getInstalledAppList():List<AppObject>
    {
        val list: ArrayList<AppObject> = arrayListOf()
        val untreatedAppList = packageManager.getInstalledApplications(0)
        for (untreatedApp in untreatedAppList)
        {
            if ((untreatedApp.flags and applicationInfo.flags) !== 0)
            {
                var appName: CharSequence = untreatedApp.loadLabel(packageManager)
                var appPackageName = untreatedApp.packageName
                var appImage = untreatedApp.loadUnbadgedIcon(packageManager)
                var app = AppObject(appPackageName, appName, appImage)
                println(appName)
                if (!list.contains(app)) {
                    list.add(app)
                }
            }
        }
        return list
    }

我在运行窗口中得到了这个结果:

代码语言:javascript
运行
复制
I/System.out: Tethering
I/System.out: Android Services Library
I/System.out: Phone and Messaging Storage
I/System.out: Dynamic System Updates
    Cell Broadcast Service
I/System.out: Calendar Storage
    com.android.providers.media
I/System.out: External Storage
I/System.out: Companion Device Manager
    MmsService
I/System.out: Download Manager
    Circular
I/System.out: Media Storage
I/System.out: Time Zone Updater
    com.android.systemui.plugin.globalactions.wallet
I/System.out: Downloads
I/System.out: Google Play Store
I/System.out: PacProcessor
I/System.out: Sim App Dialog
I/System.out: Certificate Installer
I/System.out: com.android.carrierconfig
I/System.out: Android System
I/System.out: Android R Easter Egg
I/System.out: MTP Host
I/System.out: Nfc Service
    com.android.ons
I/System.out: SIM Toolkit
    com.android.backupconfirm
I/System.out: Permission controller
    com.android.emulator.radio.config
I/System.out: Settings Storage
    com.android.sharedstoragebackup
I/System.out: SecureElementApplication
I/System.out: Input Devices
I/System.out: Emu01 display cutout
I/System.out: Markup
    com.android.cellbroadcastreceiver
I/System.out: Network manager
I/System.out: Call Management
    Rounded
I/System.out: Key Chain
I/System.out: com.android.service.ims.RcsServiceApp
I/System.out: Package installer
I/System.out: Google Play services
I/System.out: Google Services Framework
I/System.out: com.google.android.overlay.permissioncontroller
    com.google.android.overlay.emulatorconfig
I/System.out: Call Log Backup/Restore
    com.android.localtransport
I/System.out: CarrierDefaultApp
I/System.out: ProxyHandler
I/System.out: Work Setup
I/System.out: Sounds
I/System.out: Emulator Multi Display Provider
I/System.out: Presence
I/System.out: Live Wallpaper Picker
I/System.out: com.google.android.sdksetup
    com.android.server.NetworkPermissionConfig
I/System.out: Go Time
I/System.out: Settings
I/System.out: Carrier Provisioning Service
    VpnDialogs
I/System.out: Phone Services
I/System.out: Shell
    Filled
I/System.out: com.android.wallpaperbackup
I/System.out: Blocked Numbers Storage
I/System.out: User Dictionary
I/System.out: Emergency information
I/System.out: Fused Location
I/System.out: System UI
I/System.out: Bluetooth MIDI Service
I/System.out: System Tracing
I/System.out: Bluetooth
I/System.out: Contacts Storage

现在,这将返回一批系统应用程序,这当然不是首选的,但它仍然没有显示显示在本地应用程序抽屉中的用户应用程序,如YouTube或Clock。本地应用程序抽屉,我错过了什么?我认为问题可能比我的代码更深,因为我见过像我这样的代码在许多其他人中很好地工作,而且他们似乎完全没有我的问题。

请帮帮忙,我这两天一直被困在这上面。谢谢,任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

发布于 2020-10-04 06:01:29

这是获取安装在Android上的应用程序列表的代码:

代码语言:javascript
运行
复制
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

您将在ResolveInfo中获得启动应用程序所需的所有数据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64191189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档