Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FIleNotFound open failed: EACCES (Permission denied)

I am suffering from an "open failed: EACCES (Permission denied)" on Android when I attempt to write to "/mnt/sdcard/report/". My 1st step is to create the "report" folder which doesn't work. I then attempt to write which throws the above exception. I have set <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> as a peer (outside of) the application tag. I am trying to run a JUnit instrumentation test on the emulator when I get the error. Any ideas? Code is below.

        if (mReportDir == null) {
            if (mContext.getFilesDir() != null) {
                mOutputStream = mContext.openFileOutput(fileName, 0);
            } else {
                mOutputStream = mTargetContext.openFileOutput(fileName, 0);
            }
        } else {
            File f = new File(mReportDir);
            if (!f.exists()) {
                f.mkdirs();
            }
            mOutputStream = new FileOutputStream(new File(mReportDir, fileName));
        }

mReportDir is equal to "/mnt/sdcard/report", fileName is equal to "junit-report.xml", f.mkdirs returns false I believe and the dir is never created. I'm wondering why I get permission denied. I'm trying to reuse a custom JUnit Test runner.

I've added hw.sdCard= yes to the avd settings. After launching I shell in and type mount:

~$ adb shell
# mount
rootfs / rootfs ro 0 0
tmpfs /dev tmpfs rw,nosuid,mode=755 0 0
devpts /dev/pts devpts rw,mode=600 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
none /acct cgroup rw,cpuacct 0 0
tmpfs /mnt/asec tmpfs rw,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,mode=755,gid=1000 0 0
none /dev/cpuctl cgroup rw,cpu 0 0
/dev/block/mtdblock0 /system yaffs2 ro 0 0
/dev/block/mtdblock1 /data yaffs2 rw,nosuid,nodev 0 0
/dev/block/mtdblock2 /cache yaffs2 rw,nosuid,nodev 0 0

Again, I am launching the AVD programmatically from an Ant script. Is there something I can do programmatically to mount the sdcard?

like image 443
Cliff Avatar asked Dec 27 '22 17:12

Cliff


1 Answers

Found the problem! When I created the AVD I never specified the size of the SD card. I edited and set a size of 512MiB and now it's writeable! Thanks all who replied! :)

like image 166
Cliff Avatar answered Jan 03 '23 19:01

Cliff