1

For my Android app, i have to download image from server and i am keeping it in internal cache directory (or External cache directory if it is available then). Sometimes some of my users phones gets crashed because of

context.getExternalCacheDir() returns null

So I planned to use default cache directory (ie internal) for this purpose. So my question is whether is there any chance for

context.getCacheDir() returns null?

If it is there, what is the best way to store some cache images without using Storage Permission?

AtHul Antony
  • 77
  • 1
  • 11

1 Answers1

0

context.getCacheDir()

Returns the absolute path to the directory on the filesystem where files created it will may change with time it will not null becuase its the path where your app exists.

Use File createTempFile (String prefix, String suffix, File directory)

If you want to do it with runtime permssion use third param with you internal memmory path Context.getFilesDir() or Context.getDir(String name, int mode).

Source here.

Community
  • 1
  • 1
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41