Was looking for sharing video and images on other social networking or sharing apps like facebook, gmail, shareIt etc.
Here is what i've done using the default device sharing option for my media and you can share it on all available apps on device and sharing list.
Done this using Messaging center, you need to have exact path of your video to be shared.
This is the sample of Video sharing for Image you just need to change the intent.SetType("image/*") for Droid Platform.
Here is what you have to do:
In PCL:
btnShare.Clicked += (sender, e) => { MessagingCenter.Send<string>(video.video_url, "Share"); } ;
In Droid, In your MainActivity.cs file add this method:
void Share(string fileName) { var intent = new Intent(Intent.ActionSend); intent.SetType("video/*"); var path = "file://" + Environment.ExternalStorageDirectory.AbsolutePath + "/" + "Foldername" + "/" + fileName; intent.PutExtra(Intent.ExtraStream, Uri.Parse(path)); var intentChooser = Intent.CreateChooser(intent, "Share via"); StartActivityForResult(intentChooser, ShareImageId); }
In iOS, Add this your AppDelegate.cs file:
void Share(string fileName) { var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var directoryname = Path.Combine(documents, "FolderName" + "/" + fileName); var ii = NSUrl.FromFilename(directoryname); var item = ii.Copy(); var activityItems = new[] { item }; var activityController = new UIActivityViewController(activityItems, null); var topController = UIApplication.SharedApplication.KeyWindow.RootViewController; while (topController.PresentedViewController != null) { topController = topController.PresentedViewController; } topController.PresentViewController(activityController, true, () => { }); }
Posts
Thank you. But a better way would be to use Dependecy Injection instead of MessagingCenter.
thank you! thank you! thank you!
@MicaelaPerdomo
@Patil24 Do you have any sample solution that i can follow ?
@nithinshiriya I've shared the whole code needed for this, i've used this in my project that sample solution can't share. You can follow the above code and see how it works.