【问题标题】:File sharing using Intent.ACTION_SEND gives access denied on BBM使用 Intent.ACTION_SEND 共享文件会在 BBM 上拒绝访问
【发布时间】:2014-02-07 03:01:01
【问题描述】:

我正在尝试共享我的应用程序保存的音频文件。该文件已添加到媒体商店,因此所有应用都可以访问它。

Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri fileContentUri = Uri.fromFile(finalFile);
    mediaScannerIntent.setData(fileContentUri);
    this.sendBroadcast(mediaScannerIntent);

我使用 Intent.ACTION_SEND 将文件共享给其他应用:

public void shareRecording(View view) {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    i.setType("audio/mp3");
    i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + recording.getFilePath()));
    try {
        startActivity(Intent.createChooser(i, "Share " + recording.getName()));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(this, "There are no app installed to share your audio file.", Toast.LENGTH_SHORT).show();
    }
}

与所有应用程序(如 GMail、Yahoo 邮件、Whatsapp、... 除了 BBM,它拒绝访问。 我需要做什么才能使其在 BBM 上运行?

感谢您的帮助。

更新:

我用过

Uri fileUri = Uri.parse("content://" + recording.getFilePath());

而不是

Uri fileUri = Uri.parse("file:///" + recording.getFilePath());

它适用于 BBM,但不适用于其他应用

那么,解析 URI 与“file:///”和“content://”有什么区别? 以及如何使用它来使共享适用于所有应用程序?

【问题讨论】:

    标签: android android-permissions bb-messenger


    【解决方案1】:

    解决办法是使用实​​际文件来初始化Uri对象。

    File recordingFile = new File(recording.getFilePath());
    Uri fileUri = Uri.fromFile(recordingFile);
    

    这适用于所有可以共享文件的应用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-10
      • 1970-01-01
      • 2012-05-31
      相关资源
      最近更新 更多