简体   繁体   中英

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). So, far I have tried getting all apps in Phone through this code:

        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. I have a feeling it has something to do with MIME types as mentioned in Google docs.

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.

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

   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. After this attach these list to the Listview and their adpater and all done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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