阅读更多

android 中獲取內部SD卡存儲路徑是有標準API的如下:

String internalSDPath = Environment.getExternalStorageDirectory().getAbsolutePath();

 

外部SD卡路徑的獲取方法如下:

先遍歷掛載的外部設備public ArrayList getExternalStorageList() {        ArrayList storageList = new ArrayList();        try {            StorageManager mStorageManager = (StorageManager)getSystemService("storage");            try {                Method mMethodGetPaths = mStorageManager.getClass().getMethod("getVolumeList");                Object[] list = (Object[])((Object[])mMethodGetPaths.invoke(mStorageManager));                if (list != null && list.length > 0) {                    Object[] arr$ = list;                    int len$ = list.length;                    for(int i$ = 0; i$ < len$; ++i$) {                        Object item = arr$[i$];                        StorageVolumeReflection storageVolume = new StorageVolumeReflection(this, item);                        Log.i("TEST", "storageVolume = " + storageVolume);                        if (!storageVolume.mPrimary && storageVolume.mRemovable && storageVolume.mState.equals("mounted")) {                            storageList.add(storageVolume.mPath);                        }                    }                }            } catch (Exception var10) {                var10.printStackTrace();            }        } catch (Exception var11) {            var11.printStackTrace();        }        return storageList;    }外部SD卡的路徑:ArrayList sdcardPath;sdcardPath = getExternalStorageList();Log.i("TEST", "------------>sdcardPath size: " + sdcardPath.size());if(sdcardPath.size()>0) {      Log.i("TEST", "------------>sdcardPath: " + sdcardPath.get(0));}

 創建StorageVolumeReflection 類:

public class StorageVolumeReflection {        public int mStorageId;        public String mPath;        public String mDescription;        public boolean mPrimary;        public boolean mRemovable;        public boolean mEmulated;        public int mMtpReserveSpace;        public boolean mAllowMassStorage;        public long mMaxFileSize;        public String mState;        public StorageVolumeReflection(Context context, Object reflectItem) {            Method fState;            try {                fState = reflectItem.getClass().getDeclaredMethod("getStorageId");                fState.setAccessible(true);                this.mStorageId = (Integer)fState.invoke(reflectItem);            } catch (Exception var16) {                ;            }            try {                fState = reflectItem.getClass().getDeclaredMethod("getPath");                fState.setAccessible(true);                this.mPath = (String)fState.invoke(reflectItem);            } catch (Exception var15) {                ;            }            try {                fState = reflectItem.getClass().getDeclaredMethod("getDescription");                fState.setAccessible(true);                this.mDescription = (String)fState.invoke(reflectItem);            } catch (Exception var14) {                ;            }            if (this.mDescription == null || TextUtils.isEmpty(this.mDescription)) {                try {                    fState = reflectItem.getClass().getDeclaredMethod("getDescription");                    fState.setAccessible(true);                    this.mDescription = (String)fState.invoke(reflectItem, context);                } catch (Exception var13) {                    ;                }            }            if (this.mDescription == null || TextUtils.isEmpty(this.mDescription)) {                try {                    fState = reflectItem.getClass().getDeclaredMethod("getDescriptionId");                    fState.setAccessible(true);                    int mDescriptionId = (Integer)fState.invoke(reflectItem);                    if (mDescriptionId != 0) {                        this.mDescription = context.getResources().getString(mDescriptionId);                    }                } catch (Exception var12) {                    ;                }            }            try {                fState = reflectItem.getClass().getDeclaredMethod("isPrimary");                fState.setAccessible(true);                this.mPrimary = (Boolean)fState.invoke(reflectItem);            } catch (Exception var11) {                ;            }            try {                fState = reflectItem.getClass().getDeclaredMethod("isRemovable");                fState.setAccessible(true);                this.mRemovable = (Boolean)fState.invoke(reflectItem);            } catch (Exception var10) {                ;            }            try {                fState = reflectItem.getClass().getDeclaredMethod("isEmulated");                fState.setAccessible(true);                this.mEmulated = (Boolean)fState.invoke(reflectItem);            } catch (Exception var9) {                ;            }            try {                fState = reflectItem.getClass().getDeclaredMethod("getMtpReserveSpace");                fState.setAccessible(true);                this.mMtpReserveSpace = (Integer)fState.invoke(reflectItem);            } catch (Exception var8) {                ;            }            try {                fState = reflectItem.getClass().getDeclaredMethod("allowMassStorage");                fState.setAccessible(true);                this.mAllowMassStorage = (Boolean)fState.invoke(reflectItem);            } catch (Exception var7) {                ;            }            try {                fState = reflectItem.getClass().getDeclaredMethod("getMaxFileSize");                fState.setAccessible(true);                this.mMaxFileSize = (Long)fState.invoke(reflectItem);            } catch (Exception var6) {                ;            }            try {                fState = reflectItem.getClass().getDeclaredMethod("getState");                fState.setAccessible(true);                this.mState = (String)fState.invoke(reflectItem);            } catch (Exception var5) {                ;            }        }        public String getVolumeState(Context context) {            return "";        }        public boolean isMounted(Context context) {            return this.getVolumeState(context).equals("mounted");        }        public String getDescription() {            return this.mDescription;        }        public String getUniqueFlag() {            return "" + this.mStorageId;        }        public long getAvailableSize() {            return 0L;        }        public long getTotalSize() {            return 0L;        }        public String toString() {            return "MyStorageVolume{\nmStorageId=" + this.mStorageId + "\n, mPath='" + this.mPath + '\'' + "\n, mDescription=" + this.mDescription + "\n, mPrimary=" + this.mPrimary + "\n, mRemovable=" + this.mRemovable + "\n, mEmulated=" + this.mEmulated + "\n, mMtpReserveSpace=" + this.mMtpReserveSpace + "\n, mAllowMassStorage=" + this.mAllowMassStorage + "\n, mMaxFileSize=" + this.mMaxFileSize + "\n, mState='" + this.mState + '\'' + '}' + "\n";        }    }

 

更多相关文章

  1. EditText设置更多文字为省略号
  2. 短视频PHP源码Android 打造专属的下拉刷新 加载更多
  3. Android 1.6 支持更多的屏幕大小和分辨率
  4. NestedScrollView+RecyclerView滑动冲突问题,加载更多
  5. Activity生命周期的回调,你应该知道得更多!--Android源码剖析(上)
  6. Android中文文档v0.1 beta低调发布,期待更多同学来参加review
  7. Android公共库——图片缓存 网络缓存 下拉及底部更多ListView 公
  8. Android recyclerview实现查看更多/收起功能
  9. Android ListView列表 刷新和加载更多

随机推荐

  1. Android(安卓)JNI入门
  2. Android(安卓)Binder概述
  3. Android教父高焕堂谈Android“开源”与“
  4. Android(安卓)系统中 gps Location Servi
  5. Android(安卓)APN的设置问题--进一步讨论
  6. Android几种常见 自定义Button样式
  7. 如何学习Android及如何利用android来赚钱
  8. Solution of issue: Android(安卓)soft k
  9. 同一功能在Android不同版本进行兼容的方
  10. Android热修复之AndFix