⏹ SAF_StorageAccess Extension: Simplifying Storage Permissions

Intoduction

Introducing the StorageAccess Extension create by (me)Mr_Koder

The StorageAccess extension is a valuable addition to MIT App Inventor, offering simplified storage permissions management and Android SDK version retrieval. With this extension, developers can effortlessly handle storage-related tasks and ensure compatibility across different devices. Let’s explore how the StorageAccess extension simplifies storage access and enhances App Inventor projects.

Clarification
Starting from Android 11 (SDK level 30), Google introduced scoped storage which limits access to external storage by apps for better privacy. Here are the details:

  • Apps can still read and write files in their own specific directories in external storage.
  • For media files (Images, Videos, Audio), apps can use the MediaStore API to access shared storage.
  • For non-media files, apps need to use the Storage Access Framework (SAF) to interact with files. This allows users to select specific files or directories that your app can access. (solved by this extension)

Blocks

component_method

RequestStoragePermission
This method is used to request storage permissions from the user. If the Android SDK version is below 30, it requests the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions using ActivityCompat.requestPermissions() . If the Android SDK version is 30 or above and the app does not have the necessary permission to manage external storage, it opens the system settings page for the user to grant the permission.





component_method

OnManageExternalStoragePermissionGranted
Event is triggered within the StorageAccess extension to notify the app when the user grants the manage external storage permission.




component_method

CheckStoragePermission
this method is used to check the storage permissions of the app. If the app has the necessary permission to manage external storage on Android devices with SDK version 30 or above, it triggers the OnManageExternalStoragePermissionGranted() event and reports that the permission has been checked and granted through the true event. Otherwise,
it triggers the false event to indicate that the permission is not granted or the device’s SDK version is below 30.




component_method

OnPermissionChecked
event is triggered within the StorageAccess extension to notify the app when the permissions have been checked. It provides the app with information about whether the required storage permission is granted or not,





component_method

GetSdkVersion`
method is used to retrieve the Android SDK version of the device.




Video

AixFile

StorageAccess.aix (7.6 KB)

Thanks

3 Likes

Which extension?

This extension

Your extension deals with SAF?

Yes it returns the grant access status of SAF
in addition to request access to it

and note “This extesnion does not directly deal with the Storage Access Framework (SAF). Instead, it focuses on managing storage permissions and retrieving the Android SDK version and the grant access status.”

Nice extension.

But this is All file access permission request extension and Google does not allow apps with All file access permission without core functionality of the app to manage all files.

You are correct. As of Android 11 (API level 30), Google introduced changes to the storage permission model and introduced Scoped Storage.

With Scoped Storage, apps are encouraged to access files within their own app-specific directories or use the (SAF) for accessing files outside their own directories.

This Extension includes a request for the “MANAGE_EXTERNAL_STORAGE” permission, which grants all file access. Google’s policy requires that apps justify the need for this permission and demonstrate core functionality that requires such broad access to manage all files. Without a legitimate need for this permission, apps may be rejected from the Google Play Store.

1 Like