如题所述
æ¬æå®ä¾è®²è¿°äºAndroidç¼ç¨å¤æSDå¡æ¯å¦åå¨å使ç¨å®¹éæ¥è¯¢å®ç°æ¹æ³ãå享ç»å¤§å®¶ä¾å¤§å®¶åèï¼å
·ä½å¦ä¸ï¼
1.å¤æSDå¡æ¯å¦åå¨ è¿åtrue表示åå¨
/* å¤æSDå¡æ¯å¦åå¨ è¿åtrue表示åå¨ */
public boolean avaiableMedia() {
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
2.è·åSDå¡å¯ç¨ç©ºé´
/* è·åSDå¡å¯ç¨ç©ºé´ */
public long getSDFreeSize() {
// åå¾SDå¡æ件路å¾
File path = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
// è·åå个æ°æ®åç大å°(Byte)
long blockSize = sf.getBlockSizeLong();
// 空é²çæ°æ®åçæ°é
long freeBlocks = sf.getAvailableBlocksLong();
// è¿åSDå¡ç©ºé²å¤§å°
// return freeBlocks * blockSize; //åä½Byte
// return (freeBlocks * blockSize)/1024; //åä½KB
return (freeBlocks * blockSize) / 1024 / 1024; // åä½MB
}
3.è·åSDå¡ææ空é´
/* è·åSDå¡ææç©ºé´ */
public long getSDAllSize() {
// åå¾SDå¡æ件路å¾
File path = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
// è·åå个æ°æ®åç大å°(Byte)
long blockSize = sf.getBlockSizeLong();
// è·åæææ°æ®åæ°
long allBlocks = sf.getBlockCountLong();
// è¿åSDå¡å¤§å°
// return allBlocks * blockSize; //åä½Byte
// return (allBlocks * blockSize)/1024; //åä½KB
return (allBlocks * blockSize) / 1024 / 1024; // åä½MB
}
1.å¤æSDå¡æ¯å¦åå¨ è¿åtrue表示åå¨
/* å¤æSDå¡æ¯å¦åå¨ è¿åtrue表示åå¨ */
public boolean avaiableMedia() {
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
2.è·åSDå¡å¯ç¨ç©ºé´
/* è·åSDå¡å¯ç¨ç©ºé´ */
public long getSDFreeSize() {
// åå¾SDå¡æ件路å¾
File path = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
// è·åå个æ°æ®åç大å°(Byte)
long blockSize = sf.getBlockSizeLong();
// 空é²çæ°æ®åçæ°é
long freeBlocks = sf.getAvailableBlocksLong();
// è¿åSDå¡ç©ºé²å¤§å°
// return freeBlocks * blockSize; //åä½Byte
// return (freeBlocks * blockSize)/1024; //åä½KB
return (freeBlocks * blockSize) / 1024 / 1024; // åä½MB
}
3.è·åSDå¡ææ空é´
/* è·åSDå¡ææç©ºé´ */
public long getSDAllSize() {
// åå¾SDå¡æ件路å¾
File path = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
// è·åå个æ°æ®åç大å°(Byte)
long blockSize = sf.getBlockSizeLong();
// è·åæææ°æ®åæ°
long allBlocks = sf.getBlockCountLong();
// è¿åSDå¡å¤§å°
// return allBlocks * blockSize; //åä½Byte
// return (allBlocks * blockSize)/1024; //åä½KB
return (allBlocks * blockSize) / 1024 / 1024; // åä½MB
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2015-03-28
点击设置-存储
第2个回答 2015-03-28
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
// sd card 可用
}else {
// 当前不可用
}本回答被提问者和网友采纳
Environment.MEDIA_MOUNTED)) {
// sd card 可用
}else {
// 当前不可用
}本回答被提问者和网友采纳
第3个回答 2015-03-28
系统软件是可以自动识别的!