【问题标题】:Android share ListView contentAndroid 分享 ListView 内容
【发布时间】:2014-04-10 23:32:49
【问题描述】:

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

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

但没有成功!谢谢

【问题讨论】:

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

标签: android listview mp3 share


【解决方案1】:

如果有的话,很少有 Android 应用程序设置有处理 android.resource 方案的 <intent-filter>。将文件复制到内部存储和use FileProvider,或者只是use my StreamProvider(用于传输资源),以使用content Uri

【讨论】:

    【解决方案2】:

    确保资源路径正确。

    假设您的 res/raw/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!"));
    }
    

    【讨论】:

      【解决方案3】:

      试试这个...

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多