Is there a way to save to internal storage?
Taifun
July 18, 2022, 11:17pm
2
Yes you can
You might want to elaborate, what exactly you are trying to do...
See also
Before you ask a question / open a new topic
please take care of the following points:
The forum was previously searched for similar topics / issues.
Give a precise (detailed) description of
the issue / bug,
the goal.
Show the (relevant) blocks (images, screenshots of blocks in high quality).
Debug your blocks (connect to Companion and right mouse click: → Do it).
Name the Android / iOS version running on your (test) device.
Do not open multiple threads on the same topic.
If you haven't al…
Taifun
1 Like
I am trying to create a csv file for my app but it won't create the file. I have seen a lot of forum threads and have found no solution. Please help me! I don't have an sd card on my phone so I don't know if that is the reason why or not. But here is my code and I wanted to know if there is anything wrong with it.
Anke
July 18, 2022, 11:21pm
4
filipeedensilva:
internal storage?
Read this first to understand the difference between external and internal storage and then specify your question.
From an Android point of view there are an → Internal Storage and an → External Storage .
1. Internal Storage
The Internal Storage can only be accessed with a rooted device.
1.1 The app package is saved in
/data/data/<packageName>/
In order to be able to debug your app, AI2 saves the assets for → Companion on devices with
Android ≥ 10 (API ≥ 29):
/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/assets/
Android < 10 :
/storage/emulated/0/Android/data/edu.mit…
1 Like
Okay, I am creating an app that creates football (soccer) statistics. I capture the 1st and 2nd half stats and add them to a label that is then created into a csv file.
I have tried creating the file but it hasn0t worked yet.
Taifun
July 18, 2022, 11:25pm
6
You are not able to store in arbitrary directories anymore... try storing to shared storage... for example /Download
Taifun
1 Like
Okay, I changed the directory to /Document
, that should be okay yes? And the DefaultFileScope shoulb be set to shared right?
Thank you! I understand now what External storage means
Hello Filipe
Google introduced security measures that prevent Apps making their own directories/files on SD. Where you save your file depends on it's purpose. If it is to be read on your device by another App, it needs to be saved to a shared directory. If it is only for your App to read, save it in the ASD (App Specific Directory).
Guide:
How to save a file (text, Canvas: image) read and share it on all Android versions.
[grafik]
Note:
You cannot share a text file from the → Private dir (internal storage):
/data/user/0/<packageName>/files/
A little trick/tip....
Drag out a canvas to your project, set it to 1x1 pixels in size, but keep it visible.
Drag out a File component
Use these blocks...
[blocksgetASD]
Works in Companion and for compiled apps, tested on Android 10
(should work across all android versions....returning the root of the sdcard in pre 10)
The ASD did not exist before Android 10.
1 Like
Yes, you're right. I misspelled the word.
Anke
July 18, 2022, 11:45pm
12
No, it must be Legacy
, because on Android 11+ WRITE
permission must also be (incorrectly) declared in the Manifest. And this is the only option that does this.
Or you can use my MFile
extension.
Here is a modified version of Sunny's EFile extension, which added some methods that are needed (among others things) for testing purposes with Companion & AKP. Because if you try to save in one of the Shared folders (/Documents or /Download) first with Companion it is not possible to do this without deleting the saved text file before testing with the APK and vice versa (at least on Android 11+). So the Delete & FileExists & API level methods are needed.
The Delete method exists with the File …
Search the forum, I've pointed out this bug countless times and how to work around it.
1 Like
I'm going to use the MFile extension, it seems better to use. Could you please explain to me what I have to do to make it work?
Anke
July 19, 2022, 12:06am
14
Take a look at the blocks I've shown in the description of the extension:
1 Like
Sorry for asking but what does the mfile.sdkversion mean?
Anke
July 19, 2022, 12:12am
16
API level (Android version) of the device.
Example : If API < 30 (Android < 11), then ask for WRITE
permission.
Anke
July 19, 2022, 12:15am
17
Read this for deeper understanding:
Access to non-media files on Android 11+
On Android 11+, non-media files (like txt, pdf, csv, ...) can be accessed
if and only if
the text files are in the → ASD or in the → Private dir (i.e. were saved there), or
the text files are in one of the Shared folders /Documents or /Download and
these files were created by the app itself, or
SAF is used, or
MANAGE_EXTERNAL_STORAGE* permission is requested and granted.
*` This is not really an option, because an app that requests this permi…
filipeedensilva:
I have another question, it's not really related to this but it's still related to my app. The screen orientation is set to horizontal on the entire app but everytime I change screen, the screen orientation goes vertical and then instantly goes horizontal, and because of that it sort of glitches for half a second in between screens. Is there anyway to fix this?
Create a new Forum Topic for this issue Filipe.
2 Likes
system
Closed
July 26, 2022, 1:01am
20
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.