Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

ShareActionProvider on Android [v7.Widget.ShareActionProvider]

$
0
0

Hey Guys.

Now that we have AppCompat support I'm curious if someone got the ShareActionProvider to work.

I tried to follow this BlogPost but it is not getting displayed. Maybe someone knows how to get it working.

Here's my code:

[Activity(Label = "Sparen statt schuften", Icon = "@drawable/icon",Theme="@style/StandardTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    private Android.Support.V7.Widget.ShareActionProvider _actionProvider;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        ToolbarResource = Resource.Layout.Toolbar;
        TabLayoutResource = Resource.Layout.TabLayout;
        //ActionBar.SetIcon(Resource.Drawable.Iconfree);

        if (!Insights.IsInitialized)
        {
            Insights.Initialize("removed", this);
            Insights.Identify(Insights.Traits.GuestIdentifier, null);
        }
        global::Xamarin.Forms.Forms.Init(this, bundle);
        SvgImageRenderer.Init();
        LoadApplication(new App());
    }

    public override bool OnCreateOptionsMenu(IMenu menu)
    {
        MenuInflater.Inflate(Resource.Menu.menu, menu);

        var shareItem = menu.FindItem(Resource.Id.action_share);
        var test = MenuItemCompat.GetActionProvider(shareItem);
        _actionProvider = test.JavaCast<Android.Support.V7.Widget.ShareActionProvider>();

        var intent = new Intent(Intent.ActionSend);
        intent.SetType("text/plain");
        intent.PutExtra(Intent.ExtraText, "Test");

        _actionProvider.SetShareIntent(intent);

        return base.OnCreateOptionsMenu(menu);
    }
}

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>