免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

andorid storagetotalandfree-創新互聯

1 在Setting應用中,storage 顯示total and free code:

成都創新互聯公司專注于網站建設|網頁維護|優化|托管以及網絡推廣,積累了大量的網站設計與制作經驗,為許多企業提供了網站定制設計服務,案例作品覆蓋垃圾桶等行業。能根據企業所處的行業與銷售的產品,結合品牌形象的塑造,量身策劃品質網站。
final File path = VolumeInfo.getPath();
final long freeBytes = path.getFreeSpace();
final long totalBytes = path.getTotalSpace();
final long usedBytes = totalBytes - freeBytes;

final String used = Formatter.formatFileSize(context, usedBytes);
final String total = Formatter.formatFileSize(context, totalBytes);
2 VolumeInfo.java 是hidden的,只能通過反射得到。代碼如下:
try {
    StorageManager sManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
    Class class_StorageManager = StorageManager.class;
    Method method_getVolumes = class_StorageManager.getMethod("getVolumes");

    List<Object> volumes = (List<Object>) method_getVolumes.invoke(sManager);

    mClassType = Class.forName("android.os.storage.VolumeInfo");

    for (Object volumeInfo : volumes) {

        mGetMethod = mClassType.getDeclaredMethod("getPath");
        File path = (File) mGetMethod.invoke(volumeInfo);
        final long freeBytes = path.getFreeSpace();
        final long totalBytes = path.getTotalSpace();
        final long usedBytes = totalBytes - freeBytes;

        Log.i("cyy1","freeBytes="+Formatter.formatFileSize(context,freeBytes));

        Log.i("cyy1","usedBytes="+Formatter.formatFileSize(context,usedBytes));

         mGetMethod1 = mClassType.getDeclaredMethod("getId");
        String  id = (String) mGetMethod1.invoke(volumeInfo);
        Log.i("cyy1","id="+id);
    }



}catch (Exception e){
    Log.i("cyy1",e.getMessage());
    e.printStackTrace();
}
得到數據:
08-18 17:28:31.087 32148-32148/ I/cyy1: freeBytes=190 MB
08-18 17:28:31.088 32148-32148/ I/cyy1: usedBytes=22.68 GB
08-18 17:28:31.088 32148-32148/ I/cyy1: id=private
08-18 17:28:31.088 32148-32148/ I/cyy1: freeBytes=9.90 MB
08-18 17:28:31.088 32148-32148 I/cyy1: usedBytes=22.84 GB
08-18 17:28:31.088 32148-32148/ I/cyy1: id=emulated
其中emulated 是external stroage的數據。而private 是data的數據

3 可以通過以下code驗證:
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSizeLong();
long blockCount = stat.getBlockCountLong();
long availableBlocks = stat.getAvailableBlocksLong();
long avaibByte =   stat.getAvailableBytes();
Log.i("cyy","avaibByte="+Formatter.formatFileSize(context,avaibByte));
long free= stat.getFreeBytes();
Log.i("cyy","free="+Formatter.formatFileSize(context,free));

String totalSize = Formatter.formatFileSize(context, blockCount*blockSize);
String availableSize = Formatter.formatFileSize(context, availableBlocks*blockSize);

Environment.getExternalStorageDirectory() 跟emulated 數據一致;Environment.getDataDirectory()       
和private數據一致。

另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

新聞名稱:andorid storagetotalandfree-創新互聯
文章地址:http://newbst.com/article42/dgghec.html

成都網站建設公司_創新互聯,為您提供軟件開發域名注冊企業網站制作響應式網站網站設計公司虛擬主機

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

網站建設網站維護公司