为什么moto手机(960x540)判断SD Card不起作用? 本帖最后由 yiyaaixuexi 于 2012-01-04 10:09:42 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果bytesAvailable > 1048576; megAvailable >= 1如果bytesAvailable < 1048576 megAvailable = 0应该转成浮点计算吧 首先无论你是不是有sd卡都会,你的判断条件得到的都是挂载sdcard;这个就已经不对了所以可以猜测到你的手机应该可能还有一个虚拟的外置存储你可以用这段代码试试:File storageFile = android.os.Environment.getExternalStorageDirectory().getAbsoluteFile(); Debug.log(Tag, "getCurrentAllMountedStoreDisk:storageFile==" + storageFile, FlagDebug); int count = 0; try { File CanonicalFile = storageFile.getCanonicalFile(); File external = CanonicalFile.getParentFile(); Debug.log(Tag, "getCurrentAllMountedStoreDisk:CanonicalFile,external==" + CanonicalFile+","+external, FlagDebug); if (!external.getAbsolutePath().equals(File.separator)) { File[] file = external.listFiles(); for (int i = 0; i < file.length; i++) { File tmp = file[i]; if (tmp.canRead() && tmp.canWrite() && tmp.isDirectory() && !tmp.isHidden()) { Debug.log(Tag, "getCurrentAllMountedStoreDisk:file:" + tmp.getAbsolutePath(), FlagDebug); ret.add(tmp.getAbsolutePath()); count++; } } } } catch (IOException e) { Debug.log(Tag, "initMount()", e, FlagDebug); }你打印下看是不是有别的目录,sdcard 可能是/mnt/sdcard 你可能还有什么/mnt/flash之类的如果有 你在看着区别处理 1楼的方法试一下另外你的机器是什么机机型,有的把NAND做为/sdcard,外置SD只是其下一个目录而已 Boolean sdcardpresent = android.os.Environment.getExternalStorageState().equals (android.os.Environment.MEDIA_MOUNTED);这个判断SD Card是否存在有什么问题呢? 我现在要做5个分辨率 应对三款手机的 别的手机这个判断都是没问题的 但是在moto 960x540的时候 无论我是否有SD Card 返回的值都是 true 怎么回事? 其实下面只是判断 SD Card是否已满而已 各种厂商可能会对自己的机器做一些特别处理因为android是开源的改来改去也没有关系,所以各家的文件存储可能都有一些区别,会自己在mnt下虚拟一个新目录存储文件,我们自己的产品就是如此 ,而且无论是否sd卡存在,也是一直mounted状态,所以这个机器可能也是那样的情况,我上面的那段代码你修改修改看看mnt下面有什么文件结构, Android ListView滚动卡 求救一个tab中放两个activity openOrCreateDatabase的问题 android 开发移动设备 求解! LINUX C++下发送AT指令给GSM模块? Android模拟器账户与同步设置,同步功能已关闭,如何打开啊? Android 蓝牙连接时候那个弹出框是怎么实现的? 如何结束安卓进程 Eclipse不小心因为断电关闭了,打开之后项目全是红叉 Android广播问题 android应用中如何实现注销功能 android网络编程问题
如果bytesAvailable < 1048576 megAvailable = 0
应该转成浮点计算吧
所以可以猜测到你的手机应该可能还有一个虚拟的外置存储
你可以用这段代码试试:File storageFile = android.os.Environment.getExternalStorageDirectory().getAbsoluteFile();
Debug.log(Tag, "getCurrentAllMountedStoreDisk:storageFile==" + storageFile, FlagDebug);
int count = 0;
try {
File CanonicalFile = storageFile.getCanonicalFile();
File external = CanonicalFile.getParentFile();
Debug.log(Tag, "getCurrentAllMountedStoreDisk:CanonicalFile,external==" + CanonicalFile+","+external, FlagDebug);
if (!external.getAbsolutePath().equals(File.separator)) {
File[] file = external.listFiles();
for (int i = 0; i < file.length; i++) {
File tmp = file[i];
if (tmp.canRead() && tmp.canWrite() && tmp.isDirectory() && !tmp.isHidden()) {
Debug.log(Tag, "getCurrentAllMountedStoreDisk:file:" + tmp.getAbsolutePath(), FlagDebug);
ret.add(tmp.getAbsolutePath());
count++;
}
}
}
} catch (IOException e) {
Debug.log(Tag, "initMount()", e, FlagDebug);
}
你打印下看是不是有别的目录,sdcard 可能是/mnt/sdcard 你可能还有什么/mnt/flash之类的
如果有 你在看着区别处理
另外你的机器是什么机机型,有的把NAND做为/sdcard,外置SD只是其下一个目录而已