Get Chosen App from Intent.createChooser

血红的双手。 提交于 2019-12-04 06:25:08

As of API level 22 it is now actually possible. In Android 5.1 a method (createChooser (Intent target, CharSequence title, IntentSender sender)) was added that allows for receiving the results of the user's choice. When you provide an IntentSender to createChooser, the sender will be notified by the chooser dialog with the ComponentName chosen by the user. It will be supplied in the extra named EXTRA_CHOSEN_COMPONENT int the IntentSender that is notified.

I am trying to capture the result of Intent.createChooser to know which app a user selected for sharing.

That is not possible.

Other "choosing" solutions, like ShareActionProvider, may offer more. I have not examined the Intent handed to onShareTargetSelected() to see if it contains the ComponentName of the chosen target, though the docs suggest that it should.

And, if for some reason it does not, you are welcome to try to fork ShareActionProvider to add the hooks you want.

The reason why createChooser() cannot be handled this way is simply because the "choosing" is being done by a separate process from yours.

I have the following code in my MainActivity, but the onShareTargetSelected method is never getting called.

ShareActionProvider goes in the action bar. You cannot just create an instance, call a couple of setters, and expect something to happen.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!