Xamarin Forms Display image in default gallery application

FebinDonzManGroveFebinDonzManGrove USMember ✭✭
edited April 2016 in Xamarin.Forms

Hi,

i have a requirement to display image in the gallery application.

in android, i could easily done using below piece of code

Intent intent = new Intent(); intent.AddFlags (ActivityFlags.NewTask); intent.SetAction(Intent.ActionView); intent.SetDataAndType(Android.Net.Uri.Parse(imageURL), "image/*"); Application.Context.StartActivity ( intent );

is there any similar way in ios ?

thanks in advance.

Answers

  • AlmaJensen.9398AlmaJensen.9398 USMember ✭✭✭

    You should check out the Media Plugin from James Montemango along with many of the other Xamarin Plugins. They work both inside and out of Xamarin forms. For your particular situation you'd need the Media plugin.

  • FebinDonzManGroveFebinDonzManGrove USMember ✭✭
    edited April 2016

    thanks Alma Jensen for the support.

    using media plugin i can take / browse picture from / to gallery. But my requirement is that, when i click a particular image that should open in the default gallery application on the device. so that i can do pinch zoom / share kind of things.

    finally i got some thing from iOS forums,

                Xamarin.Forms.Device.BeginInvokeOnMainThread(() => 
                {
                    var firstController = UIApplication.SharedApplication.KeyWindow.RootViewController.ChildViewControllers.First().ChildViewControllers.Last().ChildViewControllers.First();
    
                    var navcontroller = firstController as UINavigationController;
    
                    var uidic = UIDocumentInteractionController.FromUrl(new NSUrl(imageURL, true));
    
                    uidic.Delegate = new DocInteractionC(navcontroller); 
    
                    uidic.PresentPreview(true);
    
                });
    
    
    
        public class DocInteractionC : UIDocumentInteractionControllerDelegate
        {
            readonly UINavigationController _navigationController;
    
            public DocInteractionC(UINavigationController controller)
            {
                _navigationController = controller;
            }
    
            public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
            {
    
                return _navigationController;
    
            } 
    
            public override UIView ViewForPreview(UIDocumentInteractionController controller)
            {
    
                return _navigationController.View;
    
            }
    
        }
    
    
    

    thank you all.

  • mario.moramario.mora USMember ✭✭

    Hi
    It looks like this doesn't work for ios 10...
    anybody has a workaorund?

  • MarkMeeusMarkMeeus BEMember ✭✭

    @mario.mora I just fixed an issue where the UIDocumentInteractionController wouldn't open anymore in iOS 10. I'm not sure if you are having the same issue, but in my case the issue was gone when I made sure the image file had a proper.

    Also, explicitly passing uti 'public.image' seems to break the UIDocumentInteractionController on iOS 10.

  • mario.moramario.mora USMember ✭✭

    @MarkMeeus said:
    @mario.mora I just fixed an issue where the UIDocumentInteractionController wouldn't open anymore in iOS 10. I'm not sure if you are having the same issue, but in my case the issue was gone when I made sure the image file had a proper.

    Also, explicitly passing uti 'public.image' seems to break the UIDocumentInteractionController on iOS 10.

    thank you MarkMeeus, but I've found a fix within this thread: https://forums.xamarin.com/discussion/comment/225628/#Comment_227550

    In the end I replaced the UIDocumentInteractionController for a QLPreview

Sign In or Register to comment.