美文网首页Android技术知识Android开发Android开发
[Android Framework]获取U盘设备状态

[Android Framework]获取U盘设备状态

作者: 80ec6268dd8e | 来源:发表于2018-07-20 10:19 被阅读10次

    获取U盘信息

        mStorageManager = StorageManager.from(this);
        final StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
        for (StorageVolume volume : storageVolumes) {
            if (!volume.isEmulated()) {
        
    
                }
            }
        }
    

    U盘设备状态和路径

    import android.os.storage.StorageManager;
    import android.os.storage.StorageEventListener;
    private StorageManager mStorageManager;
    
    
     mStorageManager = StorageManager.from(this);
     
    
    //注册和反注册
    
    mStorageManager.registerListener(mStorageListener);
    
    
    if (mStorageManager != null && mStorageListener != null) {
        mStorageManager.unregisterListener(mStorageListener);
    }
    
    
        /**
         *
         * 监听  path  路径    oldState 上一个状态      newState 当前状态
         *  所有状态 mounted   unmounted     removed     checking
         */
        StorageEventListener mStorageListener = new StorageEventListener() {
            @Override
            public void onStorageStateChanged(String path, String oldState, String newState) {
                Log.i("qkmin -voolesettings"," StorageEventListener Received storage state changed notification that " + path +
                        " changed state from " + oldState + " to " + newState);
                
      
            }
        };
    
    
    

    相关文章

      网友评论

        本文标题:[Android Framework]获取U盘设备状态

        本文链接:https://www.haomeiwen.com/subject/cqxspftx.html