android - how to get photo absolute path from removable SD card -
android - how to get photo absolute path from removable SD card -
background information
i have been writing backup photos service, needs photo absolute paths android external storage (like photos stored in 'dcim' directory , subdirectores) , upload them remote server. problem how validate photo absolute paths android device. since there vast bulk of android devices, it`s tough ensure get-photo-absolute-path algorithm reach validate photos gallery directory , traverse photos paths within of it.
now app supports uploading photos primary external storage (not secondary external storage, removable sd card). that`s say.
if device has 1 emulated external storage (on-board flash), photographic camera upload service can scan photo paths on correctly. if device has removable storage (like sd card), photographic camera upload service can scan photo paths correctly well.the algorithm above scans photo paths primary external storage works correctly. when comes
if device both has emulated external storage , removable storage, photographic camera upload service scans photo paths on emulated external storage (primary storage), bulk of users save photos 16g or bigger size removable sd card (secondary storage) ignored app, that`s problem. see finish issue here. code implementationto absolute photo path internal storage, hard coded "external directory list",
string[] paths = { "/dcim", "/dcim/camera", "/dcim/100media", // many samsung phones mount external sd card /sdcard/external_sd "/external_sd/dcim", "/external_sd/dcim/camera", "/external_sd/dcim/100media" };
and combined absolute path like
string fullpath = environment.getexternalstoragedirectory().getabsolutepath() + path;
i know that`s not best practice, that`s why inquire help. btw, see finish external directory list
questionto absolute photo paths android storage
check if external storage mounted, scan photos internal storage default. can fit bulk of getting photo path requirements, see finish implementation here let user choose specific directory upload photos sd card (if mounted one)so wonder if proposal above right or not? comments or reference appreciated.
edit different manufacturers set sd card mounted point differently, there no regular rules that, impossible (or say, bad practice) scan , upload photos app in background automatically. photos path sd card, practical way think scan root directories, shows such directories in file browser window let user choose specific gallery directory , persist path locally instead of scanning app itself. because it`s error prone scan photos directives automatically on sd card.
you can seek way
for popupprivate void selectimage() { final charsequence[] items = { "camera", "gallery","cancel" }; alertdialog.builder builder = new alertdialog.builder(detail_mul.this); builder.settitle("add photo!"); builder.setitems(items, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int item) { if (items[item].equals("camera")) { intent intent = new intent(mediastore.action_image_capture); file f = new file(android.os.environment.getexternalstoragedirectory(), "temp.jpg"); intent.putextra(mediastore.extra_output, uri.fromfile(f)); startactivityforresult(intent, request_camera); } else if (items[item].equals("gallery")) { intent intent = new intent(intent.action_pick,android.provider.mediastore.images.media.external_content_uri); intent.settype("image/*"); startactivityforresult(intent.createchooser(intent, "select file"),select_file); } else if (items[item].equals("cancel")) { dialog.dismiss(); } } }); builder.show(); }
for getting result @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); bitmap bm = null; if (resultcode == result_ok) { if (requestcode == request_camera) { file f = new file(environment.getexternalstoragedirectory().tostring()); (file temp : f.listfiles()) { if (temp.getname().equals("temp.jpg")) { f = temp; break; } } seek { bitmapfactory.options btmapoptions = new bitmapfactory.options(); bm = bitmapfactory.decodefile(f.getabsolutepath(),btmapoptions); bm = bitmap.createscaledbitmap(bm, 300, 200, true); string path = android.os.environment.getexternalstoragedirectory()+ file.separator+ "phoenix" + file.separator + "default"; preferencemanager.getdefaultsharedpreferences(getbasecontext()).edit().putstring("endum_image_"+count, f.tostring()).commit(); outputstream fout = null; file file = new file(path, string.valueof(system.currenttimemillis()) + ".jpg"); seek { fout = new fileoutputstream(file); bm.compress(bitmap.compressformat.jpeg, 85, fout); fout.flush(); fout.close(); } grab (filenotfoundexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } grab (exception e) { e.printstacktrace(); } } grab (exception e) { e.printstacktrace(); } } else if (requestcode == select_file) { uri selectedimageuri = data.getdata(); //getrealpathfromuri(selectedimageuri); string temppath = getpath(selectedimageuri, detail_mul.this); preferencemanager.getdefaultsharedpreferences(getbasecontext()).edit().putstring("endum_image_"+count, temppath).commit(); bitmapfactory.options btmapoptions = new bitmapfactory.options(); bm = bitmapfactory.decodefile(temppath,btmapoptions); bm = bitmap.createscaledbitmap(bm, 300, 200, true); bm = bitmapfactory.decodefile(temppath, btmapoptions); } } }
android file-upload image-uploading photo-gallery photo-upload
Comments
Post a Comment