Check Mobile App
Read now
Start a Project

How to use ShareActionProvider in Action Bar

Save

In this blog,
I will show you how to create a share button in the Action Bar of the MainActivity.

For implementing this we will use ShareActionProvider available in Android.

 

How to implement

For creating share action, we have to do two things.

First, we have to need a menu item with property actionProviderClass having the value android.widget.ShareActionProvider.

Second thing is to set a share intent for this menu . This can be done in the callback function onCreateOptions.

Step 1:

Define the android:actionProviderClass attribute for the corresponding <item>

share_menu.xml

Step 2: Set the Share Intent

Next, call MenuItem.getActionProvider() to retrieve an instance of ShareActionProvider.

You may only need to set the share intent once during the creation of your menus, or you may want to set it and then update it as the UI changes.

 

 

Source:

developer.android.com

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.

Osama
Talk to Sales

Global

Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home