czy1121/update

Nexus 6 Android 6.0.1 文件读写异常

Closed this issue · 5 comments

java.io.FileNotFoundException: /storage/emulated/0/Android/data/ezy.demo.update/cache/56cf48f10e4cf6043fbf53bbbc4009e3: open failed: EACCES (Permission denied)
05-09 18:11:59.841 30251-30892/ezy.demo.update W/System.err: at libcore.io.IoBridge.open(IoBridge.java:452)
05-09 18:11:59.841 30251-30892/ezy.demo.update W/System.err: at java.io.RandomAccessFile.(RandomAccessFile.java:117)
05-09 18:11:59.841 30251-30892/ezy.demo.update W/System.err: at ezy.boost.update.UpdateDownloader$LoadingRandomAccessFile.(UpdateDownloader.java:236)
05-09 18:11:59.841 30251-30892/ezy.demo.update W/System.err: at ezy.boost.update.UpdateDownloader.download(UpdateDownloader.java:184)
05-09 18:11:59.842 30251-30892/ezy.demo.update W/System.err: at ezy.boost.update.UpdateDownloader.doInBackground(UpdateDownloader.java:78)
05-09 18:11:59.842 30251-30892/ezy.demo.update W/System.err: at ezy.boost.update.UpdateDownloader.doInBackground(UpdateDownloader.java:34)
05-09 18:11:59.842 30251-30892/ezy.demo.update W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
05-09 18:11:59.842 30251-30892/ezy.demo.update W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-09 18:11:59.842 30251-30892/ezy.demo.update W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
05-09 18:11:59.842 30251-30892/ezy.demo.update W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
05-09 18:11:59.842 30251-30892/ezy.demo.update W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
05-09 18:11:59.842 30251-30892/ezy.demo.update W/System.err: at java.lang.Thread.run(Thread.java:818)
05-09 18:11:59.842 30251-30892/ezy.demo.update W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
05-09 18:11:59.843 30251-30892/ezy.demo.update W/System.err: at libcore.io.Posix.open(Native Method)
05-09 18:11:59.843 30251-30892/ezy.demo.update W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
05-09 18:11:59.843 30251-30892/ezy.demo.update W/System.err: at libcore.io.IoBridge.open(IoBridge.java:438)
05-09 18:11:59.843 30251-30892/ezy.demo.update W/System.err: ... 11 more
05-09 18:11:59.876 30251-30251/ezy.demo.update I/ezy.update: [3004]下载失败:磁盘读写错误

读写权限申请了,在模拟器器上可以正常下载文件,其他手机也可以,就是我的Nexus6不 行

6.0权限有些需要运行时授权,你可以添加运行时检查来处理,最好的解决办法还是作者更新库,这样其他人使用也就可以避免了。

我已经申请过权限了,还是不行的

另外原因已经找到了,其他手机上是可以的,但是可能是我的 Moto Nexus6比较特殊吧,作者源码里是获取context.getExternalFilesDir()作为下载目录,我换成了Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)就可以正常下载安装了(前提需要申请读取读写外部目录的权限)

另外还有个坑,在我的手机上(Moto Nexus6), context.getFileDir()作为下载目录也不行,虽然会下载成功,但是无论如何安装会提示“解析安装包异常”,换成外部公共目录就没问题,我也是醉了