2017-04-24 192 views
0

我的工作共享功能Instagram的分享問題:總是我得到的消息「無法加載圖片」

我已經有問題,Instagram的分享

這裏是我的代碼:

  • 我想分享存儲在「繪製」 folder.This「賬戶」的形象僅僅是一個例子

    try { 
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
        shareIntent.setType("image/*"); 
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        Uri uri = Uri.parse("android.resource://com.example.swathi.booklender/drawable/account"); 
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 
        shareIntent.setPackage("com.instagram.android"); 
        startActivity(shareIntent); 
    }catch (Exception e) 
    { 
        Toast.makeText(getActivity(),"No Activity available, install instagram",Toast.LENGTH_LONG).show(); 
        e.printStackTrace(); 
    } 
    

如何擺脫這個問題?

回答

0

您不能共享繪製直接

首先創建一個繪製的文件,然後分享它

Intent shareIntent = new Intent(Intent.ACTION_SEND); 
shareIntent.setType("image/jpg"); 
File image = new File(getFilesDir(), "foo.jpg"); 
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image)); 
startActivity(Intent.createChooser(shareIntent, "Share image via")); 
+0

想,如果我從Web服務獲得的圖像,在這種情況下我也必須存儲在Android的圖像設備,那麼只有我可以分享對嗎? – kavie

+0

@dya是的。當您嘗試使用意圖共享圖像時,您必須爲其他應用程序提供一個uri來獲取圖像。因爲其他應用程序無法訪問您的res文件。 –

+0

,謝謝你的代碼幫助我解決問題 – kavie