Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-28231

Android: Change Ti.Filesystem.externalStorageDirectory to use scoped storage

    Details

      Description

      Summary:
      The Android 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() 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.

      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

          Activity

            People

            • Assignee:
              jquick Joshua Quick
              Reporter:
              jquick Joshua Quick
              Reviewer:
              Gary Mathews
              Tester:
              Lokesh Choudhary
            • Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Integration