Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28231] Android: Change Ti.Filesystem.externalStorageDirectory to use scoped storage

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2020-11-16T21:39:39.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.3.0
ComponentsAndroid
Labelsandroid, externalstorage, filesystem
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-11-06T04:33:16.000+0000
Updated2020-11-16T21:39:39.000+0000

Description

*Summary:* The Android [externalStorageDirectory](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-property-externalStorageDirectory) is currently set to a location outside of "scoped storage". As of Android 10, you cannot write to this location unless you set "AndroidManfiest.xml" <application/> attribute requestLegacyExternalStorage to true. https://developer.android.com/about/versions/11/privacy/storage *Solution:* Use the folder location returned by the Java [Context.getExternalFilesDir()](https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String)) method. This is a private sandboxed directory for the app that falls under scoped storage. *Note 1:* With this change, you do *+NOT+* need the following permissions anymore. * READ_EXTERNAL_STORAGE * WRITE_EXTERNAL_STORAGE *Note 2:* With this change, you do *+NOT+* need to use the following APIs anymore. * [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:* The new folder location supports automatic back-up by the Android OS. This means when you uninstall and re-install the app, the files you've written to external storage will be restored. *Work-Around:* For apps built with Titanium 8.3.0 - 9.2x, you can read/write to externalStorageDirectory by doing the following in your "tiapp.xml" file.
<ti:app>
	<android xmlns:android="http://schemas.android.com/apk/res/android">
		<manifest>
			<!-- You MUST target Android 10 for "requestLegacyExternalStorage" support. -->
			<!-- The "requestLegacyExternalStorage" attribute is ignored by Android 11. -->
			<uses-sdk android:targetSdkVersion="29"/>
			<application android:requestLegacyExternalStorage="true"/>
		</manifest>
	</android>
</ti:app>

Attachments

FileDateSize
FileExternalTest.js2020-11-09T22:04:46.000+00001447

Comments

  1. Joshua Quick 2020-11-07

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/12253
  2. Lokesh Choudhary 2020-11-16

    FR Passed. PR Merged.

JSON Source