How to invoke PdfActivity share action programatically
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 is extending the PdfActivity
.
First, get hold of the share menu item and remove it 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:
if (shareMenuItem != null) { onOptionsItemSelected(shareMenuItem) }