java - Move and rename file in android -
i trying copy file folder in android, far, got no success. manage selected image , when taking photo, not files.
i've read , tried several solutions passed community (searched on forum , internet), none of able solve problem when copying.
first things first. added permissions manifest:
<uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.read_external_storage" />
after that, before copying file, print filepath , directory file path:
06-10 11:11:11.700: i/system.out(1442): /mimetype/storage/sdcard/misc/javascript erros submit , plan buttons in ie.doc
06-10 11:11:11.710: i/system.out(1442): /storage/sdcard/files/queue
both exists:
to copy file expected folder used fileutils:
try { fileutils.copyfile(selectedfile, dir); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); }
the problem is: no exception , file isn't there. tried solution either: how move/rename file internal app storage external storage on android?
same thing, no exception, no file either.
**edited**
this how file.
uri uri = data.getdata(); file selectedfile = new file(uri.getpath()); file dir = new file(environment.getexternalstoragedirectory(), "files/queue");
to image, way:
uri selectedimage = data.getdata(); string[] filepathcolumn = { mediastore.images.media.data }; cursor cursor = getcontentresolver().query(selectedimage,filepathcolumn, null, null, null); cursor.movetofirst(); int columnindex = cursor.getcolumnindex(filepathcolumn[0]); string picturepath = cursor.getstring(columnindex); cursor.close(); savechecklistimage(bitmapfactory.decodefile(picturepath));
i retrieve file here when call bitmapfactory.decodefile(picturepath), then, save without problem. should file follow standard well?
**solution**
i found out way in post: android real path uri.getpath()
specifically method:
private string getrealpathfromuri(uri contenturi) { string result; cursor cursor = getcontentresolver().query(contenturi, null, null, null, null); if (cursor == null) { // source dropbox or other similar local file path result = contenturi.getpath(); } else { cursor.movetofirst(); int idx = cursor.getcolumnindex(mediastore.images.imagecolumns.data); result = cursor.getstring(idx); cursor.close(); } return result;
kind of same thing doing image, in smarter way ;d
easier tought. helpers
if argument 2 directory should using copyfiletodirectory.
Comments
Post a Comment