you need to use the getter for the system sdcard accessible folder with getExternalStorageDirectory()
Copying assets folder into sd card shows permission denied in android
-
12-10-2022 - |
Domanda
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" />
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow