How can I read/write my text file in /Documents?

How can I read/write my text file in /Documents ?

use the file component together with the Scope = Shared
protip: do a search in the community to find some examples

Taifun

1 Like

My blocks do not work
Cattura
blocks11

try the relative path /Documents/Appunti.txt
Taifun

2 Likes

it's the first attempt I've made

If the text file (Appunti.txt) is created by the app itself, it is no problem to read it with the File component and / or to save new text (in the shared folder /Documents).

If the text file is not created by the app itself, but was copied into the /Documents folder by another app or manually, there are 3 options (since the app, as you said, is only for your own use):

  1. Change the targetSdkVersion to 29 (easiest way).

  2. Declare MANAGE_EXTERNAL_STORAGE in the Manifest and request this permission (to get full access to all files / directories).

  3. Save / copy Appunti.txt (manually) in the ASD, eg here:
    /storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/Documents/Appunti.txt
    and copy / move it (in the Screen.Initialize event) to the shared folder β†’ /Documents (releative path) using the app
    β†’ /storage/emulated/0/Documents/Appunti.txt (absolute path).

1 Like

How can I create it ? by saving ? I tried without success

I don't know how can I do 1,2

You could use APK Editor Studio

3 Likes

Try this APK (targetSdkVerion = 29).
Put "Appunti.txt" in the folder /Documents.

1 Like

It runs well

This is the manifest of my apps

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:debuggable="false" android:icon="@mipmap/ic_launcher" android:label="PROVA" android:name="com.google.appinventor.components.runtime.multidex.MultiDexApplication" android:networkSecurityConfig="@xml/network_security_config" android:preserveLegacyExternalStorage="true" android:requestLegacyExternalStorage="true" android:roundIcon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
    <uses-library android:name="org.apache.http.legacy" android:required="false"/>
    <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize" android:name=".Screen1" android:windowSoftInputMode="stateHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <provider android:authorities="appinventor.ai_andrea_patelli.PROVA.provider" android:exported="false" android:grantUriPermissions="true" android:name="androidx.core.content.FileProvider">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
    </provider>
</application>

what changes I have to do ?

If I understand well I can recompile my old projects, edit the apk as you showed and they can run with android 11.

Yes, but why don't you just try it yourself?
Of course, these apps cannot be released in the Play Store if they were published there after July 31, 2021.

3 Likes

I tried, I can read but not save, permission denied, please enable it in settings app.

No problem for me

1 Like

You must set DefaultFileScope to Legacy, as I've shown in my test aia:

grafik

Note: This is of course a bug, that has to be fixed soon.

3 Likes

Thank you, it runs, now I can update my old projects without problems

1 Like

Are you sure you found the solution? :upside_down_face:

2 Likes

What do you mean ?
I recompiled some old projects, I changed DefaultFileScope and targetSdkVersion, the apps run well.
I would prefer to avoid all these steps, but I don't understand how and if it can be done.
You said:
Declare MANAGE_EXTERNAL_STORAGE` in the Manifest and request this permission (to get full access to all files / directories).'
How ? I tried without success

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

Can you answer me?