Android, to save into internal Storage -
i'm testing on divice, false in line
boolean issdpresent = android.os.environment.getexternalstoragestate().equals(android.os.environment.media_mounted);
so, don't have external storage in device, correct?, how can save image on internal storage? if put line...
fileoutputstream fos = context.openfileoutput(filename, context.mode_private);
the class complete
public class imagestorage { public static string savefile(bitmap bitmap, string filename) { try { fileoutputstream out = context.openfileoutput(filename, context.mode_private); bitmap.compress(bitmap.compressformat.jpeg, 90, out); out.flush(); out.close(); } catch (exception e) { e.printstacktrace(); } } public static file getimage(string imagename) { file mediaimage = null; try { string root = environment.getexternalstoragedirectory().tostring(); file mydir = new file(root); if (!mydir.exists()) return null; mediaimage = new file(mydir.getpath() + "/images/"+imagename); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } return mediaimage; } public static boolean checkifimageexists(string imagename) { bitmap b = null ; file file = imagestorage.getimage("/"+imagename+".jpg"); string path = file.getabsolutepath(); if (path != null) b = bitmapfactory.decodefile(path); if(b == null || b.equals("")) { return false ; } return true ; }
}
the word "context" it's marked "cannot resolved". have spent 1 week issue, please me
because class not default has access context
, need pass in method (see how added context
parameter):
public static string savefile(context context, bitmap bitmap, string filename) {}
so when call it, need pass kind of context. if call activity
, can use this
.
Comments
Post a Comment