本文實例講述了 Android 7.0開發獲取存儲設備信息的方法。分享給大家供大家參考,具體如下:
成都創新互聯公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都做網站、網站建設、企業官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯網時代的定邊網站設計、移動媒體設計的需求,幫助企業找到有效的互聯網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
Android 7.0開發相較之前有不少改進,具體可參考前面的文章Android7.0版本影響開發的改進分析,這里簡單總結一下Android 7.0針對存儲設備的簡單操作方法。
MountPoint
我們通過MountPoint來描述android設備信息
private static class MountPoint { String mDescription; String mPath; boolean mIsExternal; boolean mIsMounted; long mMaxFileSize; long mFreeSpace; long mTotalSpace; }
實現mMountPathList
private final CopyOnWriteArrayList <MountPoint> mMountPathList = new CopyOnWriteArrayList<MountPoint>(); public void init(Context context) { mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); final String defaultPath = getDefaultPath(); LogUtils.d(TAG, "init,defaultPath = " + defaultPath); if (!TextUtils.isEmpty(defaultPath)) { mRootPath = ROOT_PATH; } mMountPathList.clear(); // check media availability to init mMountPathList StorageVolume[] storageVolumeList = mStorageManager.getVolumeList(); if (storageVolumeList != null) { for (StorageVolume volume : storageVolumeList) { MountPoint mountPoint = new MountPoint(); mountPoint.mDescription = volume.getDescription(context); mountPoint.mPath = volume.getPath(); mountPoint.mIsMounted = isMounted(volume.getPath()); mountPoint.mIsExternal = volume.isRemovable(); mountPoint.mMaxFileSize = volume.getMaxFileSize(); LogUtils.d(TAG, "init,description :" + mountPoint.mDescription + ",path : " + mountPoint.mPath + ",isMounted : " + mountPoint.mIsMounted + ",isExternal : " + mountPoint.mIsExternal + ", mMaxFileSize: " + mountPoint.mMaxFileSize); mMountPathList.add(mountPoint); } } IconManager.getInstance().init(context, defaultPath + SEPARATOR); }
判斷是否是外置sdcard
/** * This method checks weather certain path is external mount path. * * @param path path which needs to be checked * @return true for external mount path, and false for not external mount path */ public boolean isExternalMountPath(String path) { //LogUtils.d(TAG, "isExternalMountPath ,path =" + path); if (path == null) { return false; } for (MountPoint mountPoint : mMountPathList) { if (mountPoint.mIsExternal && mountPoint.mPath.equals(path)) { return true; } } return false; }
判斷內置存儲空間
public boolean isInternalMountPath(String path) { //LogUtils.d(TAG, "isInternalMountPath ,path =" + path); if (path == null) { return false; } for (MountPoint mountPoint : mMountPathList) { if (!mountPoint.mIsExternal && mountPoint.mPath.equals(path)) { return true; } } return false; }
更多關于Android相關內容感興趣的讀者可查看本站專題:《Android文件操作技巧匯總》、《Android視圖View技巧總結》、《Android編程之activity操作技巧總結》、《Android布局layout技巧總結》、《Android開發入門與進階教程》、《Android資源操作技巧匯總》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
本文題目:Android7.0開發獲取存儲設備信息的方法
網站地址:http://m.2m8n56k.cn/article16/jgesgg.html
成都網站建設公司_創新互聯,為您提供品牌網站建設、服務器托管、搜索引擎優化、移動網站建設、外貿建站、App設計
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯