'Why getExternalCacheDir() return null?

I am using two devices having internal memory and SD card. But in one device i am getting null value when executing context.getExternalCacheDir().

What is the reason for that?

Is it possible to make ExternalCacheDir by calling context.getExternalCacheDir().mkdir();



Solution 1:[1]

The return value description, direct from the javadoc for Context:

the absolute path to application-specific directory. May return null if shared storage is not currently available

Always read the javadoc! In this case, as other say, you may just lack permission to access it.

Solution 2:[2]

Check READ_EXTERNAL_STORAGE permission before

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Doug Stevenson
Solution 2 Mohammad Reisi