从通过Twitter应用程序的URL分享图像 - 机器人 [英] Share image from URL via Twitter app - Android

查看:277
本文介绍了从通过Twitter应用程序的URL分享图像 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分享通过Twitter的应用程序的一些文字和图片。图像源是网页的URL。 下面是我的code:

I'm trying to share some text and image via the Twitter app. The image source is a web url. Below is my code:

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的应用程序共享。我也得到一个消息,说图片无法加载。这有什么code中的问题?

But only the text is getting shared via the Twitter app. I also get a message saying "Image could not be loaded". What is the problem with this code?

推荐答案

Sourav,我想你一定分享之前下载的图片。你可以做到这一点手动,或者你可以使用类似的这个。你可以找到库的存储库如何设置和使用很容易的文档里面。

Sourav, I think you must download the picture before sharing it. You can do it manually, or maybe you could use a library like this. You can find inside the library's repository easy documentation about how to set up and use it.

在你下载的图片,你可以按照这个方法:

After you have downloaded the picture you can follow this method:

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;
}

如果您只是想模仿在飞行解析图像,共享之后将其删除。

If you simply want to simulate "Parsing image on the fly", delete it after sharing.

希望这可以帮助你!

这篇关于从通过Twitter应用程序的URL分享图像 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆