简体   繁体   中英

Android : open failed eacces permission denied

i am new to android. i have tried this code

in manifest file i wrote this

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

in java code

   File sdcard = Environment.getExternalStorageDirectory();
    //Get the text file
    File file = new File(sdcard,"store.txt");

but i am getting above exception

i want to perform file read and write operations and i am using version 4.4.2.

i am getting this error

06-14 02:19:44.491: D/Shopping Cart(1700): open failed: EACCES (Permission denied)

Under kitkat your app can only write to an app specific directory on the -removable- sd card. You get possible directories using getExternalFilesDirs().

Is your permission is right place in manifest file as

    <application>
        ...

    </application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    </manifest>

Edit

Try to edit the Emulator

  1. go to android virtual device manager and then edit the emulator
  2. set say 100 MB for Sd card for the respected emulator and say Ok
  3. save and close emulator and start
  4. path saved in DDMS is mnt/sdcard/yourfilename

it worked for me the app is not giving Error and is working

Please see more at this link Cannot Write to sdcard in Android emulator and this link Guide to Emulating an SD Card Using the Google Android Emulator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM