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
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.
OnManageExternalStoragePermissionGranted
Event is triggered within the StorageAccess extension to notify the app when the user grants the manage external storage permission.
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.
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,
GetSdkVersion`
method is used to retrieve the Android SDK version of the device.
Video
AixFile
StorageAccess.aix (7.6 KB)
Thanks