簡體   English   中英

通過Twitter應用程序從Android共享圖像 - Android

[英]Share image from URL via Twitter app - Android

我試圖通過Twitter應用程序分享一些文本和圖像。 圖像源是web url。 以下是我的代碼:

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應用程序共享。 我還收到一條消息“ 無法加載圖片 ”。 這段代碼有什么問題?

Sourav,我認為你必須在分享之前下載圖片。 你可以手動完成 ,也可以像這樣使用庫。 您可以在庫的存儲庫中找到有關如何設置和使用它的簡單文檔。

下載完圖片后,您可以按照以下方法操作:

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

如果您只是想模擬“動態解析圖像”,請在共享后將其刪除。

希望這對你有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM