java - Android App does not work correctly when delete some folders it is using -
java - Android App does not work correctly when delete some folders it is using -
i problem android app not work correctly when user delete folders using. solve this,every time app access(create or modify files) folder, function invoked ensure folder exists.
/** * ensure cache folder exists<br/> * */ public void ensurecachefolderexist(){ file cachefile = new file(audio_cache_path); if (!cachefile.exists()) { boolean returnvalue=cachefile.mkdirs(); musicutils.loge("ensurecachefolderexist no"+returnvalue); } else { musicutils.loge("ensurecachefolderexist yes"); if (cachefile.isfile()) { cachefile.delete(); } } } but returnvalue false time. seems not work. possible method set audio_cache_path folder hidden one.the scheme default file manager can not see it.but third-party ones can see, such root explorer. seems not best choice. there way solve this? audio_cache_path defined follow(just key point),i can create sure problem not caused this:
public static string getsdcardpath() { //string szdir = environment.getexternalstoragedirectory().getpath(); string szdir = environment.getexternalstoragedirectory().getabsolutepath(); if (szdir.substring(szdir.length() - 1).equals(file.separator) == false) { szdir += file.separator; } homecoming szdir; } public static final string download_local_path = hardwareutil.getsdcardpath() + "sogouappmall"; private final string audio_cache_path = download_local_path + file.separator + ".mp3";
unless storage card out of memory, not see reason why fails mkdirs. hope have manifest permission.
<uses-permission android:name="android.permission.write_external_storage"/> and rule out path issues, replace
file cachefile = new file(audio_cache_path); with
file cachefile = new file(environment.getexternalstoragepublicdirectory( environment.directory_dcim), "sogouappmall/mp3"); java android file
Comments
Post a Comment