(Take image and save to app) camera component still asks for WRITE permission

Dear all,

I am so happy to have found this community.

I have changed, as @Anke said, the Screen1 to Legacy and it works great.

of course I need to change a few settings to show it better and to add a button that turns the picture if it is not displayed the right way up. but that should be no proble

Thanks all!

2 Likes

If your App is for your use only, all is well. If you want to distribute your App via Google Play Store, the App is likely to be rejected because of the use of Legacy.

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.

this is the wrong advice, because usually apps, which use that permission are rejected by Google, see here, there are a few exceptions...

I change the category of the thread to Bugs and Other Issues

thank you @Anke
Taifun

3 Likes

@ChrisWard @Anke So is there any downside to using DefaultFileScope:Legacy? What should devs watch for, when using this option?

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).

http://ai2.appinventor.mit.edu/reference/components/storage.html#File

Your work-around Topic is a great help to everyone. It would be good if App Inventor had a switch that everyone could understand e.g. 'For Android 10 and below' and 'For Android 11 and up'.

API 30 workarounds by anonwins:

1 Like

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.

2 Likes

if in doubt, let's take a look together into the App Inventor sources

Legacy: Operations should occur using legacy logic (pre-nb186). This may break on newer Android
versions and make apps incompatible with Google Play Store guidelines.

Taifun

3 Likes

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.

1 Like

Good morning all,

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.

Thanks!

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.

Hey,

huge thanks for this. I was able to get the camera visible and take a picture but I am not able to see the taken foto in my image block. Those are my blocks.

How would I do this?

First I would try this:

set Image2.Picture to file:///storage/emulated/0/pictures/test.jpg

notice the 3 slashes (file:// + /storage)

If this doesn't work, try asking for READ permission on Screen1.Initialize


WRITE_EXTERNAL_STORAGE may be gone, but READ_EXTERNAL_STORAGE is still here.


Also you should fix those two little things:

4533d4a525fac7e0f2705c6ef52c59b2ea9cf78a

Actually this capital P thing might be the problem.

Anonwins, you rock!!!!

I fixed the 2 typose but it didn't work. I added the permissions but that also didn't work in the end it was: set Image2.Picture to file:///storage/emulated/0/pictures/test.jpg

Thank you!!!!

1 Like

Glad to hear that. I'll make sure to add this knowledge into my guide. Thank you too :slight_smile: Have a good day

  • relative path (e.g.): /Download
  • absolute path : /storage/emulated/0/Download
  • full path : file:///storage/emulated/0/Download
2 Likes

I was lucky to call it a full path then XD
Oh no I was wrong. That was the absolute path. Can't always be right

I do want to note one IMPORTANT thing with the Pro camera extention.

When using the AI companion it worked great but when I downloaded it as .apk it did not work.

When I checked the permissions, camera was denied. When using this make sure to have the following permissions initialized with screen1:

Hope this helps!

Thanks!

1 Like

I have no idea what all of you are talking about here.
What should this have to do with the Play Store and the Google Play Store guidelines?
I think, nothing.

It just ensures that the storage permissions (READ / WRITE) are both declared in the Manifest and specifies how paths are handled by components that can save / read something (e.g. Canvas).

I set DefaultFileScope = Legacy to ensure that WRITE is declared in the Manifest (for devices with Android < 10), and override Legacy for the File component if necessary.

Try this APK on all Android versions (especially Android 6 - 9, 10, 11):

The app saves a text file in the ASD (for devices with Android 10+) and copies it from there to the shared storage (e.g. /Download/myTextFiles/... and read it from there (of course without storage permissions). For devices with Android < 10, the text file is directly saved in /Download/myTextFiles/ and read from there (WRITE permission is required). The same with the Canvas component.

Check it and you might understand.

Screenshot - Designer

1 Like