How to filter specific apps for ACTION_SEND intent (and set a different text for each app)

后端 未结 12 1878
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 01:08

How can you filter out specific apps when using the ACTION_SEND intent? This question has been asked in various ways, but I haven\'t been able to gather a

12条回答
  •  名媛妹妹
    2020-11-22 01:35

    If you want a customized option then you should not rely on the default dialog provided by android for this action.

    What you need to do instead is roll out your own. You will need to query the PackageManager on which packages handle the action you require and then based on the reply, you apply filtering and customized text.

    Specifically, take a look at the method queryIntentActivities of the PackageManager class. You build the intent that would launch the default dialog (the ACTION_SEND intent), pass that to this method and you will receive a list of objects that contain info on the activities that can handle that intent. Using that, you can choose the ones you want.

    Once you build your list of packages you want to present, you need to build your own list dialog (preferably an activity with the dialog theme) which will display that list.

    One thing to note though is that it's very hard to make that custom dialog look like the default one. The problem is that the theme used in that dialog is an internal theme and cannot be used by your application. You can either try to make it as similar to the native one as you want or go for a completely custom look (many apps do that like the gallery app etc)

提交回复
热议问题