【发布时间】:2015-07-11 02:39:43
【问题描述】:
我可以从私有路径 /data/data/com.exmaple.ui/files/final.mp4 这个路径播放视频。
但无法从 子目录(如 /data/data/com.exmaple.ui/files/myVideos/final.mp4)播放,
Intent intent = new Intent(Intent.ACTION_VIEW);
File playFile = new File("/data/data/com.exmaple.ui/files/myVideos/final.mp4");
intent.setDataAndType(Uri.fromFile(playFile), "video/mp4");
startActivity(intent);
文件创建代码:
String path = getFilesDir().getAbsolutePath();
File dest = new File(path,"myVideos");
boolean mkdirs = dest.mkdirs();
File destFinal = new File(dest,"final.mp4");
destFinal.setReadable(true, false);
copyFileUsingFileStreams(inputfile,destFinal);
复制代码:
private void copyFileUsingFileStreams(File source, File dest) throws IOException {
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(source);
output = new FileOutputStream(dest);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
dest.setReadable(true);
} finally {
input.close();
output.close();
}
已经使文件可读,它不允许我像上面那样使用意图读取文件吗?
错误: 设备 1:
07-09 14:22:12.098: W/VideoView(17106): Unable to open content: file:///data/data/com.exmaple.ui/files/myVideos/final.mp4
07-09 14:22:12.098: W/VideoView(17106): java.io.IOException: setDataSource failed.
错误:设备 2:
----------Private File canRead :true Exists :true
07-09 20:06:00.636: W/System.err(19371): java.io.FileNotFoundException: /sys/class/tcon/tcon/mode: open failed: ENOENT (No such file or directory)
07-09 20:06:00.636: W/System.err(19371): at libcore.io.IoBridge.open(IoBridge.java:409)
07-09 20:06:00.636: W/System.err(19371): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
07-09 20:06:00.636: W/System.err(19371): at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
07-09 20:06:00.636: W/System.err(19371): at com.sec.android.hardware.SecHardwareInterface.sysfsWrite(SecHardwareInterface.java:100)
07-09 20:06:00.636: W/System.err(19371): at com.sec.android.hardware.SecHardwareInterface.setTconUIMode(SecHardwareInterface.java:343)
07-09 20:06:00.636: W/System.err(19371): at com.sec.android.app.videoplayer.activity.MoviePlayer$SecHWInterfaceWrapper.setTconUIMode(MoviePlayer.java:5980)
07-09 20:06:00.636: W/System.err(19371): at com.sec.android.app.videoplayer.activity.MoviePlayer$24.handleMessage(MoviePlayer.java:3644)
07-09 20:06:00.636: W/System.err(19371): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 20:06:00.636: W/System.err(19371): at android.os.Looper.loop(Looper.java:137)
07-09 20:06:00.636: W/System.err(19371): at android.app.ActivityThread.main(ActivityThread.java:5455)
07-09 20:06:00.636: W/System.err(19371): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 20:06:00.646: W/System.err(19371): at java.lang.reflect.Method.invoke(Method.java:525)
07-09 20:06:00.646: W/System.err(19371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
07-09 20:06:00.646: W/System.err(19371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
07-09 20:06:00.646: W/System.err(19371): at dalvik.system.NativeStart.main(Native Method)
07-09 20:06:00.646: W/System.err(19371): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
07-09 20:06:00.646: W/System.err(19371): at libcore.io.Posix.open(Native Method)
07-09 20:06:00.646: W/System.err(19371): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
07-09 20:06:00.646: W/System.err(19371): at libcore.io.IoBridge.open(IoBridge.java:393)
07-09 20:06:00.646: W/System.err(19371): ... 14 more
想知道 root 和 subfloder 在这里有何不同吗?提到任何限制? 文件提供者或内容提供者是选项? 谢谢 尼兹
【问题讨论】:
-
为什么有
internal,你可以复制到你的SD或者更改权限。 -
要求是从内存中存储和播放
-
requirement很可能来自不了解 Android 工作原理的人。 -
@Jared Burrows 认真的吗?忘记要求......让我知道一般......
-
我已经回答了你的问题。阅读我的第一条评论。或者你可以试试
FileProvider:stackoverflow.com/questions/21304489/…
标签: android file android-intent memory