2013-04-30 44 views
5

Instagram的份額的意圖其實我想通過意向在Android電子

I found this solution for images saved on sdcard分享的Instagram的圖片,但我想在現場圖像做相同(鏈接)

我試着用

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
    shareIntent.setType("image/*"); 
    shareIntent 
      .putExtra(
        Intent.EXTRA_STREAM, 
        Uri.parse("http://www.alliswell.biz/images/products/art/alliswell_signs/yellowB.jpg")); 
    shareIntent.setPackage("com.instagram.android"); 
    startActivity(shareIntent); 

但它不工作..請幫助。

編輯

當我開始上述意圖它會打開我的安裝Instagram的應用程序,它會立即完成的Instagram和烤麪包的消息來「無法下載文件」

其實它並沒有分別解析鏈接和圖像。什麼應該是問題?

+0

定義*不工作*。任何錯誤消息? – Raptor 2013-04-30 10:06:08

+0

「無法下載文件」。消息來自Instagram的應用程序 – 2013-04-30 10:10:21

+0

這裏同樣的問題。試圖找出圖像是否存在。 – 2013-08-09 13:01:12

回答

2

您應該使用本地文件路徑

例如: 「文件:///path/to/file/image.png」。

請注意,在路徑中包含「文件」非常重要,如果沒有這部分,它也可以顯示相同的烤麪包。

+0

照片分享中仍然存在同樣的問題。 – 2016-08-13 09:16:50

0

首先你需要從該網址下載文件。您可以參考這個代碼從URL下載圖像:

String imageUrl = "Your_Image_Url"; 

    if (imageUrl != null && !imageUrl.equals("")) { 

     String fileName = generateFileNameFromUrl(imageUrl); 

     String imageLocalPath = Environment.getExternalStorageDirectory()+ File.separator+"Your_App_Name"+ fileName; 

     if (!new File(imageLocalPath).exists()) { 

     ImageDownloadModel imageDownloadModel = new ImageDownloadModel(); 

     imageDownloadModel.setImageLocalPath(imageLocalPath); 

     imageDownloadModel.setImageUrl(imageUrl); 

     imageDownloadModels.add(imageDownloadModel); 

     } 
     ImageLoadAsynkTask imageLoadAsynkTask = new ImageLoadAsynkTask(new ImageDownloadDelegate(), imageDownloadModels, albumDir, activity); 
     imageLoadAsynkTask.execute(); 

,然後使用URI該圖像共享它的Instagram:

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
shareIntent.setType("image/*"); 
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + imageLocalPath)); 
shareIntent.setPackage("com.instagram.android"); 
activity.startActivity(shareIntent);