MediaRecorder 问题 - 当我尝试写入 sdcard 时抛出 FileNotFoundException
这是抛出的确切异常:
java.io.FileNotFoundException: /mnt/sdcard/example.mp4 (Permission denied)
我从此处复制并粘贴了示例代码。此外,我还添加了这一点代码来正确格式化我的路径:
private String sanitizePath(String path) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.contains(".")) {
path += ".3gp";
}
return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
}
以下是我的清单中包含的权限:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.STORAGE" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.front"/>
我是否遗漏了一些完全明显的东西,还是更多的东西?
Here is the exact exception that's thrown:
java.io.FileNotFoundException: /mnt/sdcard/example.mp4 (Permission denied)
I literally copied and pasted example code from here. In addition, I also added this little bit of code to format my path correctly:
private String sanitizePath(String path) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.contains(".")) {
path += ".3gp";
}
return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
}
Here are the permissions included in my manifest:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.STORAGE" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.front"/>
Am I missing something completely obvious or is it something more?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想检查手机是否处于“大容量存储模式”。
在此模式下连接 USB 线时,您无法访问 /sdcard 上的文件。
You might want to check if the phone is in "Mass Storage Mode".
When USB cable is connected in this mode, you cannot access files on /sdcard.