[TIMOB-28230] Android: Add Ti.Filesystem.externalCacheDirectory support
| GitHub Issue | n/a |
|---|---|
| Type | New Feature |
| Priority | Low |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2020-11-16T21:39:35.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 9.3.0 |
| Components | Android |
| Labels | android, cache, directory, file, filesystem |
| Reporter | Joshua Quick |
| Assignee | Joshua Quick |
| Created | 2020-11-06T03:41:48.000+0000 |
| Updated | 2020-11-16T21:39:35.000+0000 |
Description
*Summary:*
On Android and iOS, we offer an [applicationCacheDirectory](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-property-applicationCacheDirectory) property used to write temporary files to internal storage.
Android supports a sandboxed cache directory for the app on external storage, which typically provides more storage space. Unlike [externalStorageDirectory](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-property-externalStorageDirectory), the external cache directory is not automatically backed-up by the system. This makes it a good location for LARGE temporary files.
We should expose this Android-only feature via the following property.
Ti.Filesystem.externalCacheDirectory
*Note 1:*
You do *+NOT+* need the following permissions to read/write to the external cache folder.
* READ_EXTERNAL_STORAGE
* WRITE_EXTERNAL_STORAGE
*Note 2:*
You do *+NOT+* need to use the following APIs before reading/writing to this folder.
* [Ti.Filesystem.hasStoragePermissions()](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-method-hasStoragePermissions)
* [Ti.Filesystem.requestStoragePermissions()](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-method-requestStoragePermissions)
*Note 3:*
You do need to check the [isExternalStoragePresent()](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-method-isExternalStoragePresent) method to see if external storage is mounted before using this folder.
*Example:*
if (Ti.Filesystem.isExternalStoragePresent()) {
const myFile = Ti.Filesystem.getFile(Ti.Filesystem.externalCacheDirectory, 'MyFile.txt');
myFile.write('Hello World');
}
PR (master): https://github.com/appcelerator/titanium_mobile/pull/12253
FR Passed. PR Merged.