【问题标题】:Send text via chosen messenger通过选定的信使发送文本
【发布时间】:2018-10-08 17:30:57
【问题描述】:

我需要授予用户选择预装在电话上的信使(SMS、Mail、Viber、WhatsApp、Skype 等)并用它发送短信的能力。

在没有自定义视图的情况下,Android 和 iOS 上有没有办法做到这一点?只能找到通过特定应用发送消息的方法。

【问题讨论】:

    标签: android ios xamarin


    【解决方案1】:
            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)));
    

    【讨论】:

      【解决方案2】:

      谢谢,生活方式。 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);
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-02
        • 1970-01-01
        • 2015-02-23
        • 1970-01-01
        • 1970-01-01
        • 2022-01-21
        • 1970-01-01
        相关资源
        最近更新 更多