Share Image from web url on iOS and Android using custom renderers.

I have tried sharing text and some URL on both the platforms below is my code.

PCL Code :

public interface IShare
    {
        Task Show(string title, string url);
    }

I have used custom renderers for Sharing title and Url on Android:

     public class ShareRenderer : IShare
        {

            private readonly Context _context;
            public ShareRenderer()
            {
                _context = Android.App.Application.Context;
            }

            public Task Show(string productTitle, string productURL)
            {
          var contentType = "message/rfc822";
         var intent = new Intent(Intent.ActionSend);
                intent.SetType(contentType);
                intent.PutExtra(Intent.ExtraText, productTitle+"\n"+productURL ?? string.Empty);
                var chooserIntent = Intent.CreateChooser(intent, productTitle ?? string.Empty);
                chooserIntent.SetFlags(ActivityFlags.ClearTop);
                chooserIntent.SetFlags(ActivityFlags.NewTask);
                _context.StartActivity(chooserIntent);

                return Task.FromResult(true);
        }
    }

I have used custom renderers for Sharing title and Url on iOS:

     public class ShareRenderer : IShare
        {
    public async Task Show(string productTitle, string productURL)
            {
                    var items = new NSObject[] { NSObject.FromObject(productTitle), NSObject.FromObject(productURL) };
            var activityController = new UIActivityViewController(items, null);
                    var vc = GetVisibleViewController();
            NSString[] excludedActivityTypes = null;

                    if (excludedActivityTypes != null && excludedActivityTypes.Length > 0)
                        activityController.ExcludedActivityTypes = excludedActivityTypes;

                    if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                    {
                        if (activityController.PopoverPresentationController != null)
                        {
                            activityController.PopoverPresentationController.SourceView = vc.View;
               }
                    }
                    await vc.PresentViewControllerAsync(activityController, true);

         }
    }

I am able to share text and the url from the dependency the challenge part is I need to share an image from a web image url.
How do i acheive this functionality do I need to save the image in my documents and save or is there any plugin to get the job done.

Sign In or Register to comment.