2017-06-12 2 views

答えて

6

using System; 
using Xamarin.Forms; 

namespace ShareSample 
{ 
    public interface IShare 
    { 
    void Share(string subject, string message, ImageSource image); 
    } 
} 

Xamarin.Android:

using Android.App; 
using Android.Content; 
using Android.Graphics; 
using Android.OS; 
using ShareSample.Droid; 
using Xamarin.Forms; 
using Xamarin.Forms.Platform.Android; 

[assembly: Dependency(typeof(IShareService))] 
namespace ShareSample.Droid 
{ 
    public class IShareService : Activity, IShare 
    { 
    public async void Share(string subject, string message, 
    ImageSource image) 
    { 
     var intent = new Intent(Intent.ActionSend); 
     //intent.PutExtra(Intent.ExtraSubject, subject); 
     intent.PutExtra(Intent.ExtraText, message); 
     intent.SetType("image/png"); 

     var handler = new ImageLoaderSourceHandler(); 
     var bitmap = await handler.LoadImageAsync(image, this); 

     var path = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDownloads 
      + Java.IO.File.Separator + "logo.png"); 

     using (var os = new System.IO.FileStream(path.AbsolutePath, System.IO.FileMode.Create)) 
     { 
      bitmap.Compress(Bitmap.CompressFormat.Png, 100, os); 
     } 

     intent.PutExtra(Intent.ExtraStream, Android.Net.Uri.FromFile(path)); 
     Forms.Context.StartActivity(Intent.CreateChooser(intent, "Share Image")); 
    } 
} 

}

Xamarin.iOS:

using Foundation; 
using ShareSample.iOS; 
using UIKit; 
using Xamarin.Forms; 
using Xamarin.Forms.Platform.iOS; 

[assembly: Dependency(typeof(IShareService))] 
namespace ShareSample.iOS 
{ 
    public class IShareService : IShare 
    { 
    public async void Share(string subject, string message, ImageSource image) 
    { 
     var handler = new ImageLoaderSourceHandler(); 
     var uiImage = await handler.LoadImageAsync(image); 

     var img = NSObject.FromObject(uiImage); 
     var mess = NSObject.FromObject(message); 

     var activityItems = new[] { mess, img }; 
     var activityController = new UIActivityViewController(activityItems, null); 

     var topController = UIApplication.SharedApplication.KeyWindow.RootViewController; 

     while (topController.PresentedViewController != null) 
     { 
      topController = topController.PresentedViewController; 
     } 

     topController.PresentViewController(activityController, true,() => { }); 
    } 

    } 

} PCLコールDependencyServiceで

using System; 
    using Xamarin.Forms; 

namespace ShareSample 
{ 
    public class SharePage : ContentPage 
    { 
     public SharePage() 
     { 
     Button sharebutton = new Button() 
     { 
      Text = "Share", 
      HorizontalOptions = LayoutOptions.FillAndExpand, 
      VerticalOptions = LayoutOptions.CenterAndExpand, 
      TextColor = Color.White, 
      BackgroundColor = Color.Blue 

     }; 

     Image img = new Image() 
     { 
      Source = "http://www.wintellect.com/devcenter/wp-content/uploads/2013/10/Wintellect_logo.gif", 
      Aspect = Aspect.AspectFit 
     }; 

     sharebutton.Clicked += (sender, e) => 
     { 
      DependencyService.Get<IShare>().Share(" ", "Hi Balaraju. How are you?", img.Source); 
     }; 

     StackLayout stack = new StackLayout() 
     { 
      HorizontalOptions = LayoutOptions.FillAndExpand, 
      VerticalOptions = LayoutOptions.FillAndExpand, 
      BackgroundColor = Color.Aqua, 
      Children = { sharebutton } 
     }; 

     Content = stack; 
     Padding = new Thickness(0, 20, 0, 0); 
    } 
    } 
} 

不要任意のプラグインは、我々はまた、また、画像とテキストを共有することができ、

サンプルのためのDropboxのリンクを見つけてください。

https://www.dropbox.com/s/32o9uuew369yupi/ShareSample.zip?dl=0

あなたがイメージを共有したり、Facebookのようなあなたのデバイスで利用可能なperticularアプリをテキスト、お使いのデバイスにアプリケーションがなければ

(OR) 

さえずりたい場合は、ここで問題がある:

使用Xamarin.Auth

http://www.c-sharpcorner.com/article/oauth-login-authenticating-with-identity-provider-in-xamarin-forms/

http://www.c-sharpcorner.com/article/register-identity-provider-for-new-oauth-application/

https://visualstudiomagazine.com/articles/2014/04/01/using-oauth-twitter-and-async-to-display-data.aspx?m=2

https://github.com/HoussemDellai/Facebook-Login-Xamarin-Forms

+0

Isam xamarin share pluginは既にこのコードを実行していますか? – batmaci

+0

このコードにはプラットフォーム仕様のパーミッションが必要ですか? – zchpit

関連する問題