I am working on another app. With this app I have 4 textboxes that get saved to a list with tinydb when the button is pressed. This works. Also, I want to press a button which opens the camera, I take a picture and it gets saved to the tinydb as well as shown on the picture field and when the app is closed and opened at another time, the picture should still be visible at the same spot.
So, with the Companion everything works, but when I compile the app the picture taking doesn't work. It gives me the following error:
Indeed WRITE_EXTERNAL_STORAGE doesn't exist for API 30+. What I don't understand is why taking a picture using the camera needs write permissions. Because there are folders which don't need write permissions (ASD, media folders, perhaps more).
yep, I am having exactly the same problem, but I couldn't figure out if it is the camera at fault or the canvas, but looking at your post it does seem to be the camera component. hopefully a fix is devised for this asap
The Camera component saves the picture in the ASD for devices with Android > 9. This doesn't require WRITE permission, which by the way is no longer available under Android 11.
But as a work-around, the problem can be bypassed if → DefaultFileScope is set to Legacy in the Designer:
Through this READ and WRITE are declared in the Manifest for all Android versions. WRITE permission for Android 11 actually makes no sense, however, because as I said, it is no longer available under Android 11. But the (wrong) logic of the Camera component requests this permission incorrectly.
So you have to grant this permission (also on devices with Android 10+, which of course should not be the case):
What do you mean by that? DefaultFileScope = Legacy changes the storage permissions that are declared in the Manifest.
However, this does not affect whether the app is rejected in the Play Store or not.
Well, I believe there is because it is effectively circumventing Google's security measures (Android 11), but Anke thinks there is not. Anke is the expert Power User in file handling/paths. The help says that Legacy will not work on Android 11 +.(via App Inventor).
You can not make a switch for the relevant android versions. We remember that Apps are not created under a given version of Android. Apps must be universal and work the same under every version of Android.
It's best to move your thinking, towards Android 11, and forget that in older versions it was possible to save files in any folder. Create all new Apps by using Android's behavior 11. Even when we create and test APP on Android 9 or older. So we use ASD and shared folders.
That has always been the aim Patryk but the new rules on external directories have made it impossible for Android 11 Apps to support their own external paths and those who are sticking with Android 10 and below wish to continue with that capability. I'd like to see the world-wide figures on Android 11, I'm guessing that much lower versions completely out weigh it as there are whole countries where most of the population cannot afford the current super-expensive phones.
You can continue older behavior for older android versions, but only if we use such an app on our phone or for educational purposes. But I think that science no already supported methods is not a good idea, if we provide this app in the Play store, it will be rejected because it would be impossible to use it on the new Android. I think we should bring everyone on using new methods, regardless of the Android version so that it does not make a greater mess than it is.
So if I understand correctly, using the defaultfilescope in legacy mode will prevent me from putting it on google play due to it going against security or regulation standards?
What would be a reliable solution? because I will have a LOT of savable blocks in this app and before I start expanding it I would like to have a usable solution which will work 100% on older and newer versions of android.
Going with the legacy mode though is great if you don't plan to distribute it over google play!!
Thanks all and I will will wait patiently if someone has a solution.
You could check my guide: (take a look at section 1-2: using the camera)
In the guide I mention that a proper way to save to external is to use shared folders. This is future-proof. If you follow my guide, you won't have problems with write permissions, and also you don't need to change the project's file scope. What I propose is to use the Pro Camera extension, which doesn't rely on write_permissions. Still you'll have to save the photos either in the ASD, or a shared folder (/Pictures or /DCIM). Writing to those directories does not require WRITE_EXTERNAL_STORAGE and is recommended by Android.
I first mentioned it here in this thread.
What I didn't mention though is that it's future-proof. It doesn't rely on outdated permissions or legacy mode. It's pure API 30+ compatible protocol/method.
Please let me summarize one more time:
The camera component is broken: you can replace it with Pro Camera extension.
The file component is broken: you can replace it with TaifunFile extension.
Done! API 30 is yours.
You're future-proof. No manifest editing, no flags setting, nothing.
You write into the shared folders, and that's what android wants you to do.
Final disclaimer: I really don't know what "legacy mode" is. I'm not sure it's an outdated thing. The opinions vary.
From the AI2 reference page we get this:
Legacy: Files will be read from and written to the file system using the App Inventor rules prior to release nb187. That is, file names starting with a single / will be read from and written to the root of the external storage directory, e.g., /sdcard/ . Legacy functionality will not work on Android 11 or later.
But, I'm asking, /Pictures (for example) is not a valid shared folder path? In my understanding, it probably is. But maybe I'm wrong, and the only up-to-date way is to use full path (/storage/emulated/0/Pictures). I know full path works (without legacy mode). But not on the built-in components.
What is a full path anyway? (I'm getting philosophical here). There are just mount points. And what we call "file scope" sounds like "mount point" to me. But back on track, /storage/emulated/0/Pictures/myphoto.jpg is considered a full path and works well with components/extensions that don't rely on write_external permission.