Android共享ListView内容

时间:2014-04-10 23:32:49

标签: android listview mp3 share

我的音板中有很多项目,我需要分享它们。我试过这个

    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!"));
    }

但没有成功!感谢

3 个答案:

答案 0 :(得分:0)

很少(如果有)Android应用设置了<intent-filter>来处理android.resource方案。将文件复制到内部存储和use FileProvider,或仅use my StreamProvider(流式传输资源),以改为content Uri

答案 1 :(得分:0)

确保资源路径正确。

说,如果您的 res / raw / song.mp3

中有音频

然后路径应该是这样的

String path =“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!"));
}

答案 2 :(得分: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..."));