Blankj / Blankj/AndroidUtilCode

SDCardUtils.getSDCardInfo android11 targetsdk30 报错

Aperta
#1,494 1 commento 0 reazioni 1 assegnatario Rivendicata da @Blankj Vedi su GitHub
bug
Lingua principale
Java
Stelle
33.6k
Fork
10.6k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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));
}
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.