【发布时间】:2018-01-16 06:36:05
【问题描述】:
我一直在尝试实现向社交平台分享文本的功能。我尝试使用 DependencyService 的代码仅在我的电子邮件的“主题”中返回我的文本。当我尝试将文本复制到剪贴板时,这不起作用。文本也不会传递到任何其他社交平台。请查看下面的代码。我有什么遗漏吗?
IShareService(接口类)
public interface IShareService
{
void SharePageLink(string link);
}
ShareService(Android 项目中的类)
[assembly: Dependency(typeof(ShareService))]
namespace LoyaltyWorx.Droid
{
public class ShareService: IShareService
{
public void SharePageLink(string text)
{
var context = Forms.Context;
Activity activity = context as Activity;
Intent share = new Intent(Intent.ActionSend);
share.SetType("text/plain");
share.AddFlags(ActivityFlags.ClearWhenTaskReset);
share.PutExtra(Intent.ExtraSubject, "Cool");
share.PutExtra(Intent.ExtraSubject, text);
activity.StartActivity(Intent.CreateChooser(share, "Share text!"));
}
}
}
Promotions.xaml.cs(要分享的文字)
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
string shareText = "Promotion: " + store + "- " + description;
DependencyService.Get<IShareService>().SharePageLink(shareText);
}
【问题讨论】:
标签: c# xamarin xamarin.forms share