获取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);
}
};
网友评论