【问题标题】:Getting a list of Android applications using Kotlin [duplicate]使用 Kotlin 获取 Android 应用程序列表 [重复]
【发布时间】:2020-10-04 04:31:23
【问题描述】:

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

我正在尝试获取设备上的完整应用列表。当我尝试使用意图过滤器时,我只得到了斜体中提到的 3 个应用程序。这是我正在使用的功能:

    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
    }

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

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 或时钟。 Native App Drawer 我错过了什么?我认为问题可能比我的代码更深,因为我已经看到像我这样的代码与许多其他人一起工作得很好,而且他们似乎根本没有遇到我的问题。

请帮忙,过去两天我一直被困在这个问题上。谢谢,非常感谢您的帮助!

【问题讨论】:

    标签: android api android-studio kotlin intellij-idea


    【解决方案1】:

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

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
    

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

    【讨论】:

    • 嗨,阿里,我已经使用了完全相同的代码。返回的唯一 3 个应用是设置、我正在运行的应用和 Google Play。您可以在我之前提出的尚未解决的问题中看到这一点。 stackoverflow.com/questions/64165009/…
    猜你喜欢
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 2014-09-08
    • 2013-01-20
    • 2014-09-21
    • 2012-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多