Android共享列表视图内容

Android共享列表视图内容,android,listview,mp3,share,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");

我的音板上有很多东西,我需要和大家分享。我试过这个

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

但是没有成功!谢谢

如果有的话,很少有安卓应用程序是使用
来处理
Android.resource
方案的。将文件复制到内部存储器,或者仅复制(用于流式传输资源)以具有
内容
Uri

确保资源路径正确

比方说,如果你的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!"));
}
试试这个

使用Uri.from文件并将文件放在如下示例中:

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..."));

你的实际问题是什么?提供更多信息当我尝试分享声音时,例如与WhatsApp,它会说这是不可能的!!