【发布时间】: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