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
My blocks do not work
try the relative path /Documents/Appunti.txt
Taifun
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):
-
Change the
targetSdkVersion
to29
(easiest way). -
Declare
MANAGE_EXTERNAL_STORAGE
in the Manifest and request this permission (to get full access to all files / directories). -
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 theScreen.Initialize
event) to the shared folder β/Documents
(releative path) using the app
β/storage/emulated/0/Documents/Appunti.txt
(absolute path).
How can I create it ? by saving ? I tried without success
I don't know how can I do 1,2
Try this APK (targetSdkVerion = 29
).
Put "Appunti.txt
" in the folder /Documents
.
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.
I tried, I can read but not save, permission denied, please enable it in settings app.
No problem for me
You must set DefaultFileScope
to Legacy
, as I've shown in my test aia:
Note: This is of course a bug, that has to be fixed soon.
Thank you, it runs, now I can update my old projects without problems
Are you sure you found the solution?
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?