【发布时间】:2018-10-08 17:30:57
【问题描述】:
我需要授予用户选择预装在电话上的信使(SMS、Mail、Viber、WhatsApp、Skype 等)并用它发送短信的能力。
在没有自定义视图的情况下,Android 和 iOS 上有没有办法做到这一点?只能找到通过特定应用发送消息的方法。
【问题讨论】:
我需要授予用户选择预装在电话上的信使(SMS、Mail、Viber、WhatsApp、Skype 等)并用它发送短信的能力。
在没有自定义视图的情况下,Android 和 iOS 上有没有办法做到这一点?只能找到通过特定应用发送消息的方法。
【问题讨论】:
String txt = "text to share";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, txt);
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share)));
【讨论】:
谢谢,生活方式。 Xamain 的最终实现:
[iOS]
public void Send(string message)
{
var activityItems = new[] { NSObject.FromObject(message) };
var activity = new UIActivityViewController(activityItems, null);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(activity, true, null);
}
[安卓]
public void Send(string message)
{
var intent = new Intent(Intent.ActionSend);
intent.SetType("text/plain");
intent.PutExtra(Intent.ExtraSubject, "Subj");
intent.PutExtra(Intent.ExtraText, message);
_targetActivity.StartActivityForResult(Intent.CreateChooser(intent, "Title"), _resultCode);
}
【讨论】: