Blankj / Blankj/AndroidUtilCode
SDCardUtils.getSDCardInfo android11 targetsdk30 报错
Ouverte
@Blankj y travaille déjà.
Depuis le 6/5/2021.
bug
- Langage dominant
- Java
- Étoiles
- 33.6k
- Forks
- 10.6k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
SDCardUtils.getSDCardInfo方法在 android11手机 targetSdk30 报错 targetSdk28 正常
java.lang.NoSuchMethodException: android.os.storage.StorageVolume.getPath []
android11 getPath 方法被移除了 提供了getDirectory
应该使用storageVolume.getDirectory().getAbsolutePath()
Method getPathMethod = null;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
getPathMethod = StorageVolume.class.getMethod("getPath");
}
for (StorageVolume storageVolume : storageVolumes) {
boolean isRemovable = storageVolume.isRemovable();
String state = storageVolume.getState();
String path;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
path = storageVolume.getDirectory().getAbsolutePath();
} else {
path = (String) getPathMethod.invoke(storageVolume);
}
paths.add(new SDCardInfo(path, state, isRemovable));
}
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.