【问题标题】:Share image from URL via Twitter app - Android通过 Twitter 应用程序从 URL 共享图像 - Android
【发布时间】:2014-06-26 17:11:59
【问题描述】:

我正在尝试通过 Twitter 应用分享一些文本和图像。图片来源是一个网址。 以下是我的代码:

sharingIntent = new Intent(android.content.Intent.ACTION_SEND);    
sharingIntent.setType("*/*");    
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I am reading this publication, check it out here: "+bookmark_url+"");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("http://example.com/images/thumbs/file_name.jpg"));

但只有文本通过 Twitter 应用程序共享。我还收到一条消息“无法加载图像”。这段代码有什么问题?

【问题讨论】:

标签: android android-intent twitter uri android-sharing


【解决方案1】:

Sourav,我认为您必须先下载图片才能分享。你可以这样做manually,或者你可以使用像this 这样的库。您可以在库的存储库中找到有关如何设置和使用它的简单文档。

下载完图片后可以按照这个方法:

private Intent shareIntent(String bookmark_url, String imagePath){
    sharingIntent = new Intent(android.content.Intent.ACTION_SEND);    
    sharingIntent.setType("*/*");    
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I am reading this publication, check it out here: "+bookmark_url);
    sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)));
    return sharingIntent;
}

如果你只是想模拟“动态解析图像”,分享后删除。

希望对您有所帮助!

【讨论】:

  • 我在 SD 卡上的存储方面有一些限制......你能确认直接从 URL 共享图像在 Twitter 中是不可能的吗?
  • 我在 iOS 等其他平台上看到过这种情况
  • @Sourav 我无法确认无法直接从 URL 共享图像,但我很确定有两个原因:1º 你的错误很清楚:“无法加载图像”, 2º 我曾使用 PHP 的 Twitter API,我必须先下载图片,然后再用它们发送推文,因为如果我不这样做,我会获得没有像你这样的图片的文本推文。
猜你喜欢
  • 2021-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多