[英]Android ,No backup to the extern sd card (/storage/sdcard1/)
I m trying to save a file in sd card at the following path. 我正在尝试在以下路径中将文件保存在SD卡中。
Environment.getExternalStorageDirectory().getAbsolutePath() + dir + filename
if sd card state is mounted. 如果已安装sd卡状态。
String state = Environment.getExternalStorageState();
One of my user complained 我的一位用户抱怨
No backup to the extern sd card (/storage/sdcard1/)
This issue raied in Galaxy Tab2 10.1. Galaxy Tab2 10.1中出现了此问题。 I am little confused,i have nexus 4,where it has only internal memory. 我有点困惑,我有联系4,那里只有内部记忆。 and verified the same in S4,s3 and note 3 all worked fine. 并在S4,s3和note 3中验证了相同的效果。 Hope i am saving the file in right path and works fine in all devices. 希望我将文件保存在正确的路径下,并在所有设备上都能正常工作。
how do i resolve complain ? 我该如何解决投诉? any things is wrong ? 有什么事吗?
. 。
The SD card might not be ready yet. SD卡可能尚未准备好。 Consider waiting for external storage to get ready, before writing to it, as shown below. 如下所示,考虑在写入外部存储之前等待其准备就绪。
// 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.