Android 7.0開發(fā)獲取存儲設(shè)備信息的方法
本文實例講述了 Android 7.0開發(fā)獲取存儲設(shè)備信息的方法。分享給大家供大家參考,具體如下:
Android 7.0開發(fā)相較之前有不少改進(jìn),具體可參考前面的文章Android7.0版本影響開發(fā)的改進(jìn)分析,這里簡單總結(jié)一下Android 7.0針對存儲設(shè)備的簡單操作方法。
MountPoint
我們通過MountPoint來描述android設(shè)備信息
private static class MountPoint { String mDescription; String mPath; boolean mIsExternal; boolean mIsMounted; long mMaxFileSize; long mFreeSpace; long mTotalSpace; }
實現(xiàn)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; }
判斷內(nèi)置存儲空間
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; }
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android文件操作技巧匯總》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
Android編程實現(xiàn)canvas繪制餅狀統(tǒng)計圖功能示例【自動適應(yīng)條目數(shù)量與大小】
這篇文章主要介紹了Android編程實現(xiàn)canvas繪制餅狀統(tǒng)計圖功能,可實現(xiàn)自動適應(yīng)條目數(shù)量與大小的功能,涉及Android基于canvas的圖形繪制相關(guān)操作技巧,需要的朋友可以參考下2017-01-01Kotlin基礎(chǔ)通關(guān)之字符串與數(shù)字類型
這篇文章主要介紹了Kotlin基礎(chǔ)知識中的字符串與數(shù)字類型,編程中的入門知識,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08Android用 Mob 實現(xiàn)發(fā)送短信驗證碼實例
這篇文章主要介紹了Android用 Mob 實現(xiàn)發(fā)送短信驗證碼實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06Android自定義實現(xiàn)開關(guān)按鈕代碼
經(jīng)常可以看到一些選擇開個狀態(tài)的配置文件,但是外觀都不多好看。我感覺還是自定義的比較好,下面小編給大家介紹通過Android自定義實現(xiàn)開關(guān)按鈕代碼,感興趣的童鞋一起學(xué)習(xí)吧2016-05-05