Android 7.0開發(fā)獲取存儲(chǔ)設(shè)備信息的方法
本文實(shí)例講述了 Android 7.0開發(fā)獲取存儲(chǔ)設(shè)備信息的方法。分享給大家供大家參考,具體如下:
Android 7.0開發(fā)相較之前有不少改進(jìn),具體可參考前面的文章Android7.0版本影響開發(fā)的改進(jìn)分析,這里簡單總結(jié)一下Android 7.0針對(duì)存儲(chǔ)設(shè)備的簡單操作方法。
MountPoint
我們通過MountPoint來描述android設(shè)備信息
private static class MountPoint {
String mDescription;
String mPath;
boolean mIsExternal;
boolean mIsMounted;
long mMaxFileSize;
long mFreeSpace;
long mTotalSpace;
}
實(shí)現(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)置存儲(chǔ)空間
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é)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
在Android項(xiàng)目中使用AspectJ的方法
這篇文章主要介紹了在Android項(xiàng)目中使用AspectJ的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04
Android 判斷當(dāng)前網(wǎng)絡(luò)是否可用簡單實(shí)例
這篇文章主要介紹了Android 判斷當(dāng)前網(wǎng)絡(luò)是否可用簡單實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-06-06
Android 啟動(dòng)另一個(gè)App/apk中的Activity實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 啟動(dòng)另一個(gè)App/apk中的Activity實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-04-04
Flutter學(xué)習(xí)教程之Route跳轉(zhuǎn)以及數(shù)據(jù)傳遞
這篇文章主要給大家介紹了關(guān)于Flutter學(xué)習(xí)教程之Route跳轉(zhuǎn)以及數(shù)據(jù)傳遞的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Android編程實(shí)現(xiàn)長按Button按鈕連續(xù)響應(yīng)功能示例
這篇文章主要介紹了Android編程實(shí)現(xiàn)長按Button按鈕連續(xù)響應(yīng)功能,涉及Android自定義按鈕及事件響應(yīng)操作相關(guān)技巧,需要的朋友可以參考下2017-01-01

