i trying load images directory in specified path. using if statement check path been called isn't giving out error , there no result been displayed also. wouldn't mind getting know getting code of mine wrong.
public class edit extends activity { // file representing folder select using filechooser static final file dir = new file("/data/data/faceemoji.alexcz.yourfaceemoji/app_imagedir/"); // array of supported extensions (use list if prefer) static final string[] extensions = new string[]{ "png" // , other formats need }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_edit); linearlayout linearlayout = (linearlayout)findviewbyid(r.id.linearlayout); log.d("loadfilepath", dir.getabsolutepath()); if (dir.isdirectory()) { // make sure it's directory system.out.println("yes"); (file f : dir.listfiles(image_filter)) { log.d("fak", "file found"); bitmap mybitmap = bitmapfactory.decodefile(f.getabsolutepath()); imageview myimage = new imageview(this); myimage.setimagebitmap(mybitmap); linearlayout.addview(myimage); } } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_edit, menu); return true; } static final filenamefilter image_filter = new filenamefilter() { @override public boolean accept(final file dir, final string name) { (string ext : extensions) { if (name.endswith("." + ext)) { return (true); } } return (false); } }; }
you should use context.getfilesdir()
internal storage , environment.getexternalstoragedirectory()
external storage, using last 1 have add write_external_storage
if want write files.
in case guess should this:
static final file dir = new file(context.getfilesdir()+"/app_imagedir/");
even thoug put log check directory right
Comments
Post a Comment