Spinner
Spinner

Reputation: 732

Constructing an on-the-fly Intent for a ShareActionProvider

I want to use a ShareActionProvider to provide a button/submenu in my ActionBar to share a file that is generated from by my app's database. The file that will be generated depends on which tab the user is currently viewing. Since the data in the database may change, the file cannot be generated at the time the Activity is created, but must be created when the user requests to send it.

To this end, I have been following the official Android guide. Unfortunately, according to the guide,

[...] if the action provider provides a submenu of actions, then your activity does not receive a call to onOptionsItemSelected() when the user opens the list or selects one of the submenu items.

There therefore appears to be no event that I can listen for to call setShareIntent() at the correct moment:

It seems that a key event is not covered by the API. How can I achieve the functionality I need?

Upvotes: 1

Views: 260

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007296

The file that will be generated depends on which tab the user is currently viewing

Update the Intent when the user changes tabs.

Since the data in the database may change, the file cannot be generated at the time the Activity is created, but must be created when the user requests to send it.

If this is truly a file (EXTRA_STREAM), use a Uri pointing to a ContentProvider of yours that will generate the file on demand.

If by "file" you mean just adjusting EXTRA_TEXT, do that as the user changes the data (e.g., TextWatcher on EditText).

Though I agree that ShareActionProvider ideally would have a "dynamic" mode where, when the user taps it, it asks you for the Intent at that point. I haven't seen any way to do that.

Upvotes: 1

Related Questions