3

The following code is run in latest android version. A 32GB external SD card is mounted. The intent is to fetch data from SD card.

File[] externalFilesDirs = context.getExternalFilesDirs(null);

Sometimes externalFilesDirs[1] would return null which should give the path of the SD card storage. This is inconsistent issue. The issue occurs sometimes within minutes of opening the app and sometimes after hours of usage. Once the externalFilesDirs[1] value starts coming null, It would always give null until the SD card is ejected and mounted back again.

The javadoc of getExternalFilesDirs(String type) states that:

* @return the absolute paths to application-specific directories. Some
* individual paths may be {@code null} if that shared storage is
* not currently available.

Does anyone have any idea about the root cause and how can it be resolved?

0 Answers0