android - Read-only file system -


i´m trying store png file in internal memory of phone, having lot of problems after try lot of diferent ways.

i´m using code:

private void storeimage(bitmap image, string nombre) {     try {         file file = new file(nombre+".png");         file.createnewfile();         fileoutputstream fos = new fileoutputstream(file);         image.compress(bitmap.compressformat.png, 100, fos);         fos.close();     } catch (filenotfoundexception e) {         log.d(tag, "file not found: " + e.getmessage());     } catch (ioexception e) {         log.d(tag, "error accessing file: " + e.getmessage());     }   } 

but doesn´t work because logcat message:

error accessing file: open failed: erofs (read-only file system)

i don´t know how change permissions of file or if there better ways save png file in phone.

thanks!!

edit: since kitkat use of environment.getexternalstoragedirectory(); discouraged, in favor of context.getexternalfilesdir returns absolute path directory on primary shared/external storage device application can place persistent files owns. these files internal applications, , not typically visible user media. directory , content deleted upon uninstall of app , won't write_external_storage use permission use returned directory.

the code have trying write inside / read only. if want store bitmap inside sd card, have change:

file file = new file(nombre+".png"); 

into:

file root = environment.getexternalstoragedirectory(); file file = new file(root, nombre+".png"); 

these 2 lines attempt write nombre+".png" root of sdcard, polluting somehow latter. file remain there untill delete manually , accessible apps installed on phone. mounting sdcard on pc or using file browser give access well.

these lines:

final fileoutputstream fos = openfileoutput(nombre+".png", context.mode_private); image.compress(bitmap.compressformat.png, 100, fos); fos.close(); 

write file in app private space in internal storage (/data/data/you.app.name). since private app able access it. exception if have rooted phone.

to retrieve it, have use:

final fileinputstream fis = openfileoutput(nombre+".png", context.mode_private); 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -