简体   繁体   English

显示 Android 手机中安装的所有消息应用程序

[英]Display all messaging apps installed in Android phone

I want to show all messaging apps installed by user in it's phone.我想显示用户在其手机中安装的所有消息传递应用程序。 The list I am expecting is like, WhatsApp, Facebook messenger, Viber, Slack, Skype, WeChat etc (If any installed).我期待的列表是,WhatsApp、Facebook messenger、Viber、Slack、Skype、WeChat 等(如果已安装)。 So, far I have tried getting all apps in Phone through this code:因此,到目前为止,我已经尝试通过以下代码获取 Phone 中的所有应用程序:

        val pm: PackageManager = context!!.packageManager
        val i = Intent(Intent.ACTION_MAIN)
        i.addCategory(Intent.CATEGORY_LAUNCHER)
        val lst = pm.queryIntentActivities(i, 0)

        for (resolveInfo in lst) {
            Log.d(
                "Test",
                "New Launcher Found: " + resolveInfo.activityInfo.packageName
            )

This only gives me Slack app but not other messaging apps.这只会给我 Slack 应用程序,但不会给我其他消息应用程序。 I have a feeling it has something to do with MIME types as mentioned in Google docs.我感觉它与 Google 文档中提到的 MIME 类型有关。

text/*, senders will often send text/plain, text/rtf, text/html, text/json
image/*, senders will often send image/jpg, image/png, image/gif
video/*, senders will often send video/mp4, video/3gp

but I don't know how to use this info.但我不知道如何使用这些信息。 Any help would be appreciated.任何帮助,将不胜感激。 TIA!蒂亚!

add ACTION_SENDTO as action parameter while creating your intent and you should see the list of apps capable of handling messages/sms etc.在创建意图时添加ACTION_SENDTO作为操作参数,您应该会看到能够处理消息/短信等的应用程序列表。

val intent = Intent(Intent.ACTION_SENDTO) // get list of activities that can handle this type of intent val lst = pm.queryIntentActivities(intent, 0)

Here pack name refers to - apps package name这里的包名指的是-apps package名

   fun appinstalled(){
    var app_names = mutableListOf<String>()
    val app_package = mutableListOf<String>()
    val packagelist: MutableList<PackageInfo> =  packageManager.getInstalledPackages(0)
    var appname : String
    var packname : String


    for (i in packagelist.indices) {
        val packageinfo : PackageInfo= packagelist[i]


        appname=packageinfo.applicationInfo.loadLabel(packageManager).toString()
        packname=packageinfo.packageName
        app.add(appname)
        app-package.add(packname)




    }

this will the list of app installed in the user device as well as their package name.这将是安装在用户设备中的应用程序列表以及它们的 package 名称。 After this attach these list to the Listview and their adpater and all done.在此之后将这些列表附加到 Listview 及其适配器并完成所有操作。

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

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