android - Permissions for getExternalCacheDir() and getCacheDir() -
my http library caching http responses. current implementation select directory cache data looks this:
public static file getdiskcachedir(context c) { file dir = c.getexternalcachedir(); if (dir == null) dir = c.getcachedir(); return dir; }
the idea use getexternalcachedir()
first option because assume there more space available getcachedir()
. official docs states free space in getcachedir()
shouldn't large (1 mb?)
you should have reasonable maximum, such 1 mb, amount of space consume cache files, , prune files when exceeding space.
my maximum space 40 mb.
so have 2 questions:
should use
getexternalcachedir()
? apps minsdk = 14. or should usegetcachedir()
?if should use
getexternalcachedir()
permissions required? according official documentation:
starting in kitkat, no permissions required read or write returned path; it's accessible calling app. applies paths generated package name of calling application. access paths belonging other packages, write_external_storage and/or read_external_storage required.
so understanding write_external_storage (includes permission read, @ least prior api 19) required work getexternalcachedir()
prior kitkat (api 19).
so permission have set is:
<uses-permission android:name="android.permission.write_external_storage" android:maxsdkversion="19"/>
right? see related bugs on lollipop this: why need write_external_storage permission getexternalcachedir() on android lollipop?
should add try-catch
block around getexternalcachedir()
, use getcachedir()
fallback?
Comments
Post a Comment