【问题标题】:Is It possible to send an image and a text file, both using a single Intent in android?是否可以在 android 中使用单个 Intent 发送图像和文本文件?
【发布时间】:2014-01-29 12:38:46
【问题描述】:

问题是(可能是重复的),但我找不到正确的答案,所以再次在这里提问。
在我的应用程序中,我需要使用一个意图来共享图像和文本文件。
我读了一些答案,例如:
ACTION_SEND sending both an Image and Text in the same Intent,
Send Image and Text both using ACTION_SEND or ACTION_SEND_MULTIPLE
还有Problems sharing combined text and image with SHARE INTENT

并尝试在我的应用程序中实现给定的解决方案,但没有一个对我有用。

目前我实现的代码如下:

Intent share = new Intent(Intent.ACTION_SEND);
        share.putExtra(Intent.EXTRA_SUBJECT, "I found movie "+movieTitle+" on Movies Tracker!");
        share.putExtra(Intent.EXTRA_TEXT, "my text");
        share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        share.setType("image/*");
        share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(Intent.createChooser(share, "Share via"));

所以现在我的问题是:有没有办法以单一意图共享图像和文本文件?
如果可能,请就这个问题提供帮助。
提前致谢。

【问题讨论】:

  • 意图共享意图 = 新意图(意图.ACTION_SEND); Uri screenshotUri = Uri.parse("file:///sdcard/image.jpg"); sharedIntent.setType("image/*"); sharedIntent.putExtra(Intent.EXTRA_TEXT, "新状态的正文"); sharedIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri); startActivity(Intent.createChooser(sharingIntent, "分享图片使用"));
  • 您需要如何发送图像,即从可绘制文件夹或从 sdcard 发送图像?

标签: android image android-intent text


【解决方案1】:

试试这个

   private void initShareIntent(String type,String _text){
     File filePath = getFileStreamPath("<span class="skimlinks-unlinked">shareimage.jpg</span>");  //optional //internal storage
     Intent shareIntent = new Intent();
     shareIntent.setAction(Intent.ACTION_SEND);
     shareIntent.putExtra(Intent.EXTRA_TEXT, _text);
     shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath)));  //optional//use this when you want to send an image
     shareIntent.setType("image/jpeg");
     shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
     startActivity(Intent.createChooser(shareIntent, "send"));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多