Question

hi friends i used this code copy my assets folder into SD card but it shows permission denied but i given the external storage permission

copy assets

         private void CopyAssets() { 
    AssetManager assetManager = getAssets(); 
    String[] files = null; 
    try { 
        files = assetManager.list(""); 
    } catch (IOException e) { 
        Log.e("tag", e.getMessage()); 
    } 
    for(String filename : files) { 
        InputStream in = null; 
        OutputStream out = null; 
        try { 
          in = assetManager.open(filename); 
          out = new FileOutputStream("/sdcard/" +"Good"); 
          copyFile(in, out); 
          in.close(); 
          in = null; 
          out.flush(); 
          out.close(); 
          out = null; 
        } catch(Exception e) { 
            Log.e("tag", e.getMessage()); 
        }        
    } 
} 
private void copyFile(InputStream in, OutputStream out) throws IOException { 
    byte[] buffer = new byte[1024]; 
    int read; 
    while((read = in.read(buffer)) != -1){ 
      out.write(buffer, 0, read); 
    } 
}

Logcat it shows permission denied

                 02-16 21:25:14.227: E/tag(405): /sdcard/Good (Permission denied)
                 02-16 21:25:14.236: E/tag(405): images
                 02-16 21:25:14.236: E/tag(405): sounds
                 02-16 21:25:14.236: E/tag(405): webkit

And this is my manifest file permission tags

                 <uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
Était-ce utile?

La solution

you need to use the getter for the system sdcard accessible folder with getExternalStorageDirectory()

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top