This answer has no solution, I rate this task impossible without fully rolling your own.
I totally agree, it should pull the data using a listener when it's required, but at the same time it works this way because it shows only the apps that can handle the intent.
It means that you have to provide the intent before being able to share it, to let the <intent-filter>
s do their thing and filter the incompatible activities. The problem comes when the filter contains a <data>
element which filters the Uri and MimeType.
Let's try to work around this.
Use OnShareTargetSelectedListener
@hannes arch was on to something, but the answer is missing from the answer which would be doSomeStuff
's implementation.
Ah it returns boolean, let's update the intent and do a startActivity(intent)
and return true
to signify we handled it.
It turns out that ShareActivityChooserModelPolicy
ignores the return value of onShareTargetSelected
, so we can't use that.
Doing so kind of works, but it'll open to of the same activities with different content (the original intent and the modified one). Not so kind to the user.
Extend ShareActionProvider
and replicate logic needed for ShareActivityChooserModelPolicy
and return the value returned from the listener. This way our return true
would work. Instead it doesn't. We lose the ability to have history of selected apps.
Extend ShareActionProvider
take 2
I tried and tried, there's just no possible way to extends this class, even with nasty reflection and setAccessible
calls. It's too rigid.
Copy ShareActionProvider
and related classes. Nope, it won't work it has some Android internal class depedencies.
Closing words
I just wonder what
the behavior is extensible and extensions of ShareActionProvider can perform different behaviors and ranking based on the history file (if appropriate).
means from https://developer.android.com/guide/topics/ui/actionbar.html