AndroidUtilCode 获取存储卡信息异常

f3temu5u  于 4个月前  发布在  Android
关注(0)|答案(2)|浏览(52)

描述 Bug

某些Android设备上会出现 SDCardUtils.getSDCardInfo() 后报错

  • AndroidUtilCode 的版本:utilcodex:1.31.1
  • 出现 Bug 的设备型号:非品牌手机,OEM设备
  • 设备的 Android 版本:API 22

相关代码

SDCardUtils.getSDCardInfo()

异常堆栈

java.lang.IllegalArgumentException: Invalid path: /mnt/usb_storage/USB_DISK0
    at android.os.StatFs.doStat(StatFs.java:46)
    at android.os.StatFs.<init>(StatFs.java:39)
    at com.blankj.utilcode.util.FileUtils.getFsTotalSize(FileUtils.java:1415)
    at com.blankj.utilcode.util.UtilsBridge.getFsTotalSize(UtilsBridge.java:305)
    at com.blankj.utilcode.util.SDCardUtils$SDCardInfo.<init>(SDCardUtils.java:177)
    at com.blankj.utilcode.util.SDCardUtils.getSDCardInfo(SDCardUtils.java:94)
    at UsbPathGetter.getWholePaths(UsbPathGetter.java:54)
xhv8bpkk

xhv8bpkk1#

我们碰到相似的问题,原因是外置SD卡坏掉了,在调用到getSDCardInfo的时候就会抛这个异常。建议把IllegalArgumentException抓一下吧。我这用的版本是1.30.6.

2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Invalid path: /storage/sdcard1
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at android.os.StatFs.doStat(StatFs.java:51)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at android.os.StatFs.<init>(StatFs.java:41)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at com.blankj.utilcode.util.FileUtils.getFsTotalSize(FileUtils.java:1415)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at com.blankj.utilcode.util.UtilsBridge.getFsTotalSize(UtilsBridge.java:305)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at com.blankj.utilcode.util.SDCardUtils$SDCardInfo.<init>(SDCardUtils.java:177)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at com.blankj.utilcode.util.SDCardUtils.getSDCardInfo(SDCardUtils.java:68)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at com.blankj.utilcode.util.SDCardUtils.getMountedSDCardPath(SDCardUtils.java:116)

2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1155)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5939)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	... 8 more
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: Caused by: android.system.ErrnoException: statvfs failed: ENOENT (No such file or directory)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at libcore.io.Linux.statvfs(Native Method)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at libcore.io.BlockGuardOs.statvfs(BlockGuardOs.java:333)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at android.system.Os.statvfs(Os.java:570)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	at android.os.StatFs.doStat(StatFs.java:49)
2023-02-17 09:19:36.588  2865  2865 E AndroidRuntime: 	... 19 more
eqoofvh9

eqoofvh92#

Please accept this pull request as soon as possible.

@Blankj

相关问题