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.

    // 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) {

Then, invoke the share action by calling the following:

if (shareMenuItem != null) {