2014-04-10 22 views
0

我有我的音板的許多項目,我需要分享他們。我已經嘗試了本Android的份額ListView的內容

private void shareImage(int resId) { 

     Intent share = new Intent(Intent.ACTION_SEND); 

     // If you want to share a png image only, you can do: 
     // setType("image/png"); OR for jpeg: setType("image/jpeg"); 
     share.setType("audio/mp3"); 

     // Make sure you put example png image named myImage.png in your 
     // directory 
     String imagePath = "android.resource://com.example.app/" + resId; 

     File imageFileToShare = new File(imagePath); 

     Uri uri = Uri.fromFile(imageFileToShare); 
     share.putExtra(Intent.EXTRA_STREAM, uri); 

     startActivity(Intent.createChooser(share, "Share Image!")); 
    } 

但沒有更迭!謝謝

+0

什麼是您的實際問題?提供更多信息 – Libin

+0

當我嘗試分享聲音時,例如WhatsApp,它說這是不可能的! – user3437592

回答

0

很少,如果有的話,安卓應用程序設置與處理android.resource計劃的<intent-filter>。將文件複製到內部存儲器和use FileProvideruse my StreamProvider(流式資源),代之以具有contentUri

0

確保資源路徑正確。

說,如果你有一個聲音在你的RES /生/ Song.mp3的

則路徑應該是這樣的

字符串路徑=「android.resource:// PACKAGENAME/res /「+ Integer.toString(R.raw.song);

示例代碼這樣的..

private void shareAudio(int resId) { 
    Intent share = new Intent(Intent.ACTION_SEND); 
    share.setType("audio/mp3"); 
    String path = "android.resource://com.example.app/res/" + Integer.toString(resId); 
    share.putExtra(Intent.EXTRA_STREAM, Uri.parse(path)); 
    startActivity(Intent.createChooser(share, "Share Audio!")); 
} 
+0

我在列表視圖中有很多項目,所以我需要使用resId! – user3437592

+0

好的。看到我更新的回答 – Libin

+0

它不起作用... – user3437592

0

嘗試......

使用Uri.fromFile,把你的文件這樣的例子:

Intent i = new Intent(android.content.Intent.ACTION_SEND); 
File your_file = new File("your path"); 
i.setType("plain/text"); 
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(your_file)); 
startActivity(Intent.createChooser(i,"Share..."));