Search code examples
androidkotlinandroid-sharing

Limiting the available apps in Android Sharesheet


I've done a bunch of Google, but I don't see any answers to this. My requirement is that we need to share content to Microsoft Teams, and only Teams.

Obviously we have seen that Android's Sharesheet is the go-to method for sharing content between apps, however I have not found a way to limit which apps appear in the Sharesheet.

Is there a way to limit the apps, i.e. whitelist Teams?

I'm also exploring the method of using an Intent with the Teams package name.


Solution

  • Is there a way to limit the apps, i.e. whitelist Teams?

    Craft an Intent that limits its scope to an application ID for Teams via setPackageName().

    Also, when you call startActivity(), make sure that you wrap your call in a try/catch block and deal with the case where the user does not have that app available to them, as you will get an ActivityNotFoundException.

    I'm also exploring the method of using an Intent with the Teams package name.

    That is your only option. It is a fragile option, insofar as Microsoft can ship as many apps described as "Teams" as Microsoft wants to. You might also see if Microsoft has a dedicated API for sharing with their Teams app(s).