This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/android/knowledge-base/invoking-share-action-programmatically.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. How to invoke the PdfActivity share action programmatically

To move the share action out of the main toolbar of PdfActivity, first hide the item with a ToolbarItemsProvider in your activity subclass:

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setToolbarItemsProvider { defaultItems ->
defaultItems.filter { it.id != PdfActivity.MENU_OPTION_SHARE }
}
}

Then trigger the same action from your own UI. Dispatching the item’s action to the ToolbarCoordinator runs the SDK’s handler exactly as a tap on the item would. It opens the sharing menu with Open, Print, and Save As…:

nutrientToolbarCoordinator().dispatch(ToolbarAction.ItemClicked(PdfActivity.MENU_OPTION_SHARE))

Two narrower entry points skip the menu:

  • showSaveAsDialog() on PdfActivity and PdfUiFragment opens the Save As dialog directly.
  • DocumentSharingManager.shareDocument() shares the document through the system share sheet. A SharingOptions instance controls the file name, the page range, and whether annotations are flattened.

To add your own entries to the sharing menu instead, see CustomSharingMenuExample in the Catalog app and PdfUi.setSharingActionMenuListener.