2012-07-19 43 views
2

如何發佈圖像和文本到instagram? 沒有問題,如果我必須打開Instagram應用程序,或者如果我通過API或其他。 問題是,我找不到如何:他們只有iphone掛鉤,並且api是無法解釋的。 有人已經這樣做了,或者知道嗎? 謝謝。Android:將圖像和文字發佈到Instagram

回答

5

我懷疑Instagram developers會永遠釋放像android的鉤子的iPhone,因爲Intents已經達到了這個目的。

如果你想分享你的應用的圖像使用這樣的意圖:

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("image/jpeg"); 
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Path/To/Image.jpg")); 
startActivity(Intent.createChooser(i, "Share Image")); 

注意,這將顯示一個dialoge允許用戶挑選,推出其照片共享應用程序。

+0

這是建議的方法,你應該遵循。否則,您將需要使用Instagram API,推出自己的自定義共享內容。 – 2012-07-19 16:48:34

+0

有沒有辦法通過手機瀏覽器觸發這種情況? – Ericson578 2012-07-31 04:50:04

+0

如果用戶安裝了Instagram,那麼當用戶點擊分享按鈕時,Instagram將顯示在該列表中。如果你想通過移動網站分享,你將不得不使用上述方法使用Instagram API – slayton 2012-07-31 05:10:28

4

這適用於我....但它假定com.instagram.android的包名,它可能會更改,恕不另行通知,我想。

private void shareToInstagram(Uri imageUri){ 
    Intent i = new Intent(Intent.ACTION_SEND); 
    i.setType("image/*"); 
    i.putExtra(Intent.EXTRA_STREAM, imageUri); 
    i.setPackage("com.instagram.android"); 
    activity.startActivity(i); 
} 

你總是可以檢查是否正在使用getPackageManager()安裝com.instagram.android包......如果沒有,那就不要在意向設置的包名,讓應用程序選擇器幫助用戶選擇應用程序來共享圖像。

5

試試這個對我有用。我會用它來分享我的產品細節。我會從服務器上獲取名稱,圖像,描述等產品的詳細信息,並在應用中顯示,然後將其分享給instagram。

從服務器獲取圖像URL。

URL url = ConvertToUrl(imgURL); 
    Bitmap imagebitmap = null; 
    try { 
     imagebitmap = BitmapFactory.decodeStream(url.openConnection() 
       .getInputStream()); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

Post image and text on instagram。

// post on instagram 
      Intent shareIntent = new Intent(
        android.content.Intent.ACTION_SEND); 
      shareIntent.setType("image/*"); 
      shareIntent.putExtra(Intent.EXTRA_STREAM, 
        getImageUri(HomeActivity.this, result)); 
      shareIntent.putExtra(Intent.EXTRA_SUBJECT, sharename); 
      shareIntent.putExtra(
        Intent.EXTRA_TEXT, 
        "Check this out, what do you think?" 
          + System.getProperty("line.separator") 
          + sharedescription); 
      shareIntent.setPackage("com.instagram.android"); 
      startActivity(shareIntent); 

轉換URI字符串到URL

private URL ConvertToUrl(String urlStr) { 
try { 
    URL url = new URL(urlStr); 
    URI uri = new URI(url.getProtocol(), url.getUserInfo(), 
      url.getHost(), url.getPort(), url.getPath(), 
      url.getQuery(), url.getRef()); 
    url = uri.toURL(); 
    return url; 
} catch (Exception e) { 
    e.printStackTrace(); 
} 
return null; 

}

轉換位圖到烏里

public Uri getImageUri(Context inContext, Bitmap inImage) { 
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); 
String path = MediaStore.Images.Media.insertImage(
     inContext.getContentResolver(), inImage, "Title", null); 
return Uri.parse(path); 

}

+1

此代碼適用於圖像,我無法發送文字與圖像。 – AmeeJoshi 2015-11-18 10:14:46

+0

此代碼與圖像工作正常...無法發送文本 – 2016-08-02 06:27:30