[英]Android ,No backup to the extern sd card (/storage/sdcard1/)
我正在嘗試在以下路徑中將文件保存在SD卡中。
Environment.getExternalStorageDirectory().getAbsolutePath() + dir + filename
如果已安裝sd卡狀態。
String state = Environment.getExternalStorageState();
我的一位用戶抱怨
No backup to the extern sd card (/storage/sdcard1/)
Galaxy Tab2 10.1中出現了此問題。 我有點困惑,我有聯系4,那里只有內部記憶。 並在S4,s3和note 3中驗證了相同的效果。 希望我將文件保存在正確的路徑下,並在所有設備上都能正常工作。
我該如何解決投訴? 有什么事嗎?
。
SD卡可能尚未准備好。 如下所示,考慮在寫入外部存儲之前等待其准備就緒。
// Wait till external storage is initialized upon startup.
private void awaitExternalStorageInitialization() {
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
int count = 0;
do {
String state = Environment.getExternalStorageState();
if(count > 0) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Logger.log(e.getMessage(), Logger.LogType.ERROR, e);
}
}
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
} else {
// Something else is wrong. It may be one of many other states,
// but all we need to know is we can neither read nor write
mExternalStorageAvailable = mExternalStorageWriteable = false;
}
count++;
} while ((!mExternalStorageAvailable) && (!mExternalStorageWriteable)
&& (count < 15));
if(!mExternalStorageWriteable)
Logger.log("External storage not ready yet", Logger.LogType.ERROR, null);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.