【问题标题】:Sending text and Image simultaneously in Android在 Android 中同时发送文本和图像
【发布时间】:2014-06-02 09:44:22
【问题描述】:

在我的应用程序中,我的要求是同时发送图像和文本。所以我使用下面的代码

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_TEXT, "My photos");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+f));                       
startActivity(Intent.createChooser(share, "Share Image"));

但只有图像被发送,而文本没有被发送。我该如何解决这个问题?

【问题讨论】:

    标签: android android-intent android-sharing


    【解决方案1】:

    请试试这个

    //假设uris是一个Uri列表

    Intent intent = null;
    if (uris.size > 1){
    intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else if (uris.size() == 1) {
    intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));}
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_TEXT, "Some message");
    startActivity(Intent.createChooser(intent,"compatible apps:"));
    

    【讨论】:

      【解决方案2】:

      您将IntentMIME type 设置为image,这就是为什么只发送图像。 这样的事情会解决你的问题:

      Intent share = new Intent(Intent.ACTION_SEND);
      share.setType("*/*");
      share.putExtra(Intent.EXTRA_TEXT, "My photos");
      share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+f));                       
      startActivity(Intent.createChooser(share, "Share Image"));
      

      【讨论】:

      • 只发送文件 使用this不发送文本
      【解决方案3】:
      String message= "My photos";
      URI = Uri.parse("file://" + f);
      Intent share = new Intent(android.content.Intent.ACTION_SEND);
             share.setType("*/*");
             if (URI != null) {
              share.putExtra(Intent.EXTRA_STREAM, URI);
          }
             share.putExtra(android.content.Intent.EXTRA_TEXT, message);
      startActivity(Intent.createChooser(share, "Share Image"));
      

      这样应该没问题。

      【讨论】:

      • 只发送文本文件不使用this发送
      • 我更新了我的答案。你能实施并告诉我吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      • 2020-07-19
      • 2015-11-02
      相关资源
      最近更新 更多