android - How to deal with more than one SD card slot -


in app, store user's app data using mysqlite databases, , allow user backup app data sd card within folder create on sd card (let's call myappfolder). on android devices have single sd card slot, works fine (e.g. droid).

however, on devices such galaxy s have more 1 sd card, things don't work. unfortunately, don't have 1 of these devices, can't debug anything, can go user reports. did searching , found known issue. however, did not find solutions didn't involve hardcoding other paths used, i'm looking that.

in app, check , see if myappfolder exists. if not, create folder. folder created successfully, although created on "internal" memory slot returned getexternalstoragedirectory() when there 2 slots present. however, files not created , copied there. don't understand why folder created, files not created.

can tell me how can modify code work devices 2 card slots 1 card slot? i'd prefer not hard-code locations check, if that's way, i'll things working.

here code use(slightly modified make more readable here):

file root = environment.getexternalstoragedirectory(); string state = environment.getexternalstoragestate(); if( environment.media_mounted.equals(state)) {     file datadirectory = environment.getdatadirectory();     if (root.canwrite())     {         string savepath = root + "/myappfolder/";         file directory = new file(savepath);         if( !directory.exists() )         {             directory.mkdirs();  //folder created         }          string currentdbpath = "\\data\\my_app\\databases\\database.db";          file currentdb = new file(datdirectory, currentdbpath);         file backupdb = new file(savepath, "database.db");          if (currentdb.exists())          {             filechannel src = new fileinputstream(currentdb[i]).getchannel();             filechannel dst = new fileoutputstream(backupdb[i]).getchannel();              dst.transferfrom(src, 0, src.size());              src.close();             dst.close();         }     } 

can tell me how can modify code work devices 2 card slots 1 card slot?

"external storage" not mean "removable storage". "external storage" means "mountable storage" -- iow, user has access storage when plug device host machine via usb cable.

android, @ present, designed allow developers write things one external storage point, , device manufacturer whether fixed flash or removable. hence, should backing things external storage, not thinking backing things sd card.

can tell me how can modify code work devices 2 card slots 1 card slot?

use getdatabasepath() database path, rather gyrations presently going through. never use concatenation create paths, way root + "/myappfolder/" -- use file constructor, elsewhere. make sure hold write_external_storage permission. beyond that, should work fine device sufficient external storage hold database, regardless of how many "card slots" device may have.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -