如题所述
Android å¤æSDå¡æ¯å¦åå¨å容éæ¥è¯¢çç®åæ¹æ³å¦ä¸ï¼
è¦å¨AndroidManifest.xmlä¸å¢å SDå¡è®¿é®æé
<!-- å¨SDCardä¸å建ä¸å é¤æ件æé -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<!-- å¾SDCardåå ¥æ°æ®æé -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
è°ç¨java代ç
private boolean ExistSDCard() {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
return true;
} else
return false;
} è¿åtrue 表示å¯ç¨,false表示ä¸å¯ç¨
3.æ¥çSDå¡çå©ä½ç©ºé´
public long getSDFreeSize(){
//åå¾SDå¡æ件路å¾
File path = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
//è·åå个æ°æ®åç大å°(Byte)
long blockSize = sf.getBlockSize();
//空é²çæ°æ®åçæ°é
long freeBlocks = sf.getAvailableBlocks();
//è¿åSDå¡ç©ºé²å¤§å°
//return freeBlocks * blockSize; //åä½Byte
//return (freeBlocks * blockSize)/1024; //åä½KB
return (freeBlocks * blockSize)/1024 /1024; //åä½MB
}
4.æ¥çSDå¡æ»å®¹é
public long getSDAllSize(){
//åå¾SDå¡æ件路å¾
File path = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
//è·åå个æ°æ®åç大å°(Byte)
long blockSize = sf.getBlockSize();
//è·åæææ°æ®åæ°
long allBlocks = sf.getBlockCount();
//è¿åSDå¡å¤§å°
//return allBlocks * blockSize; //åä½Byte
//return (allBlocks * blockSize)/1024; //åä½KB
return (allBlocks * blockSize)/1024/1024; //åä½MB
}
è¦å¨AndroidManifest.xmlä¸å¢å SDå¡è®¿é®æé
<!-- å¨SDCardä¸å建ä¸å é¤æ件æé -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<!-- å¾SDCardåå ¥æ°æ®æé -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
è°ç¨java代ç
private boolean ExistSDCard() {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
return true;
} else
return false;
} è¿åtrue 表示å¯ç¨,false表示ä¸å¯ç¨
3.æ¥çSDå¡çå©ä½ç©ºé´
public long getSDFreeSize(){
//åå¾SDå¡æ件路å¾
File path = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
//è·åå个æ°æ®åç大å°(Byte)
long blockSize = sf.getBlockSize();
//空é²çæ°æ®åçæ°é
long freeBlocks = sf.getAvailableBlocks();
//è¿åSDå¡ç©ºé²å¤§å°
//return freeBlocks * blockSize; //åä½Byte
//return (freeBlocks * blockSize)/1024; //åä½KB
return (freeBlocks * blockSize)/1024 /1024; //åä½MB
}
4.æ¥çSDå¡æ»å®¹é
public long getSDAllSize(){
//åå¾SDå¡æ件路å¾
File path = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
//è·åå个æ°æ®åç大å°(Byte)
long blockSize = sf.getBlockSize();
//è·åæææ°æ®åæ°
long allBlocks = sf.getBlockCount();
//è¿åSDå¡å¤§å°
//return allBlocks * blockSize; //åä½Byte
//return (allBlocks * blockSize)/1024; //åä½KB
return (allBlocks * blockSize)/1024/1024; //åä½MB
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2016-01-31
去设置里面的储存,看看是否有外部储存