`
guojianhui0906
  • 浏览: 46145 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

android 4.0 取内外置SD卡新特性

阅读更多
private StorageManager mStorageManager = null;

    protected String mSDCardPath = null;
    protected boolean mSDCardMounted = true;
    protected boolean mSDCard2Mounted = false;
    protected String mSDCardPath = null;
    protected String mSDCard2Path = null;

 
        mStorageManager = (StorageManager)getSystemService(Context.STORAGE_SERVICE);
        String[] storagePathList = mStorageManager.getVolumePaths();
        if (storagePathList != null) {
            Log.d(TAG, "StorgaeList size: " + storagePathList.length);
            if (storagePathList.length >= 2) {
                mSDCardPath = storagePathList[0];
                mSDCard2Path = storagePathList[1];
            } else if (storagePathList.length == 1){
                mSDCardPath = storagePathList[0];
            }
        }
       
        Log.d(TAG, "SDCard path: " + mSDCardPath); //取出来的/mnt/sdcard
        Log.d(TAG, "SDCard2 path: " + mSDCard2Path);//取出来的应该是/mnt/sdcard

        mSDCardMounted = checkSDCardMount(mSDCardPath);
        mSDCard2Mounted = checkSDCardMount(mSDCard2Path);
        Log.d(TAG, "SDCard state in onCreate: " + mSDCardMounted);
        Log.d(TAG, "SDCard2 state in onCreate: " + mSDCard2Mounted);
       
    //判断sdcard是否挂载上,返回值为true证明挂载上了,否则不存在
    protected boolean checkSDCardMount(String mountPoint) {
        if(mountPoint == null){
            return false;
        }
        String state = null;
        state = mStorageManager.getVolumeState(mountPoint);
        return Environment.MEDIA_MOUNTED.equals(state);
    }

所说的4.0新特性是指针对android2.3来说的,android2.3判断内外置sdcard将在下篇文章“android 2.3 取内外置SD卡”带过,以稍作完善。


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics