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

If you want to move the share action from the main toolbar of the PdfActivity, you can use the following method from your custom activity that extends the PdfActivity.

First, remove the share menu item from the main toolbar:

override fun onCreateOptionsMenu(menu: Menu): Boolean {
// This populates the menu with main toolbar items.
super.onCreateOptionsMenu(menu)
// Store the share menu item for future use.
shareMenuItem = menu.findItem(PdfActivity.MENU_OPTION_SHARE)
// Then remove the share item from the main toolbar.
if (shareMenuItem != null) {
menu.removeItem(PdfActivity.MENU_OPTION_SHARE)
}
}

Then, invoke the share action by calling the following:

if (shareMenuItem != null) {
onOptionsItemSelected(shareMenuItem)
}