_AddPermissions("Storage");

845 views
Skip to first unread message

Chisan Gelu

unread,
Jul 29, 2022, 6:26:56 AM7/29/22
to DroidScript
Work on Android 12......but not in Android 10....

I need acces phone internal storage.....to write it...
????

Chisan Gelu

unread,
Jul 29, 2022, 6:36:04 AM7/29/22
to DroidScript
                            img = app.CreateImage(null, .3, .15);
                            img.SetPixelData(dataUrl);
                            img.Save(path);

Don.t save it on internal storage on android 10..... 
Message has been deleted
Message has been deleted
Message has been deleted

Chisan Gelu

unread,
Jul 29, 2022, 10:58:42 AM7/29/22
to DroidScript

app.Screenshot() - saves files in Pictures.....

var dt = new Date();
                            var path = app.GetSpecialFolder("Pictures") + "/Routes/" + dt.toISOString().replaceAll(":", "") + ".jpg";
                            var path2 = app.GetSpecialFolder("Pictures") + "/Routes";
                            if (!app.FolderExists(path2))
                                app.MakeFolder(path2);
                            img = app.CreateImage(null, .3, .15);
                            img.SetPixelData(dataUrl);
                            img.Save(path);

img.Save cant save file....
app.MakeFolder cant make new folder

In Android 10 .....with storage permission

Alan Hendry

unread,
Jul 29, 2022, 1:06:38 PM7/29/22
to DroidScript
HI,
Not sure what you mean by "with storage permission". Do you mean "with scoped storage".
Not sure what should be in dataUrl
For me Android 11 (go) Scoped Storage this fails to create the folder (alerts false) 
                            var path2 = app.GetSpecialFolder("Pictures") + "/Routes";
                            if (!app.FolderExists(path2))
                                app.MakeFolder(path2);
                            alert(app.FolderExists(path2))
This seems to work
                            var path = app.GetSpecialFolder("Pictures") + "/" + dt.toISOString().replaceAll(":", "") + ".jpg";

                            img = app.CreateImage(null, .3, .15);
                            img.Save(path);
Not sure where app.ScreenShot() is storing the image
In a previous post I noted that this works
function doscreenshot(){

    var dt = new Date();
    var path = app.GetSpecialFolder( "Pictures" )+"/"+dt.toISOString()+".jpg";
    alert(path)
    app.ScreenShot(path)
}
Regards, ah

Chisan Gelu

unread,
Jul 29, 2022, 1:12:02 PM7/29/22
to DroidScript
I want to make a new  folder in Pictures called Routes 
and i want to save there my image.....
in Android 12 the code works fine but in Android 10 i
Can.t do it with same code.....
I don.t know why.....

Chisan Gelu

unread,
Jul 29, 2022, 1:13:38 PM7/29/22
to DroidScript
dataUrl is an image base64 format obtained with a js library who take transform html to base64 image code.

Chisan Gelu

unread,
Jul 29, 2022, 1:45:49 PM7/29/22
to DroidScript
app.GetSpecialFolder("Pictures") + "/" + dt.toISOString().replaceAll(":", "") + ".jpg";

Android 10 only this works.....only to save directly in Pictures.

Chisan Gelu

unread,
Jul 29, 2022, 2:07:47 PM7/29/22
to DroidScript
[SOLVED]

app.GetSpecialFolder("Pictures") + "/" + "Routes" + "/" + dt.toISOString().replaceAll(":", "") + ".jpg";

Works and MakeFolder and img.Save ... path formatted like this !!!

Chisan Gelu

unread,
Jul 29, 2022, 6:12:01 PM7/29/22
to DroidScript
Work only when run from Droidscript.......when generate apk and run from app 
can.t make folder can.t save picture.....Android 10


What permission i need to add to work???

Chisan Gelu

unread,
Jul 30, 2022, 3:23:09 AM7/30/22
to DroidScript
How to add "MANAGE_EXTERNAL_STORAGE" permission ???

Can be done in build.json???

Alan Hendry

unread,
Jul 30, 2022, 6:13:14 AM7/30/22
to DroidScript
HI,

In the Premium Group 
Steve posted
"
DroidScript does not offer a way to request MANAGE_EXTERNAL_STORAGE permission because DroidScript itself does not fit the extremely tight restrictions for requesting that permission, for instance the "Core use" requirement
Personally I cannot currently see any way to offer use of that permission restricted to a small number of uses that would be likely to pass Google's strict (but inflexible) testing requirements
It is possible to access a separate external drive using SAF as in the DroidScript sample 'Sdcard_Access' but in my own apps I have given up using shared main storage for Android 11+ apps and am only using folders under the DroidScript folder "/Storage/" which point to shared main storage on traditional devices and restricted main storage on Scoped storage devices
"

Not sure why "Android 12 the code works fine but in Android 10 i ... Can.t do it with same code....."
Usually newer versions of Android add storage and access restrictions.
Can you check if Scoped Storage is in effect? https://symdstools.github.io/Docs/docs/app/IsScoped.htm
I believe that if an app is installed on an old version of Android without scoped storage, 
then Android is updated to a new version, the app can continue without scoped storage.

When your app runs under DS (or the WiFi IDE) then it runs with DS settings (including default folders) and DS access.
When you build/install/run then it runs with your settings and access.

AFAIK DS 2.51a1 is still in beta testing, it includes
- Added support for /Internal/* and /External/* SAF paths.
- app.GetPermission() now supports 'external' and 'internal' keywords.
- Replaced 'Sdcard Access' sample with 'Storage Access' sample.
- Improved permissions detection for file:///android_asset paths. 

Regards, ah

Chisan Gelu

unread,
Jul 30, 2022, 12:52:42 PM7/30/22
to DroidScript
When your app runs under DS (or the WiFi IDE) then it runs with DS settings (including default folders) and DS access.
When you build/install/run then it runs with your settings and access.


What settings... or permission DroidScript have ....i want to imitate DrodiScript setting behaviour regarding Storage Acces

Alan Hendry

unread,
Jul 31, 2022, 4:59:18 PM7/31/22
to DroidScript
HI,

Can you give a specific example of what you want to do?

There are at least 4 distinct scenarios, running under DS (or WiFi IDE or Chromebook) -vs- buiilding/installing/running your own app,
and Scoped storage -vs- nonScoped. 
In each case you have specific access to some Private Storage (belongs to your app) 
and specific access to some Shared Storage (available to other apps as well). 

AFAIK DS doesn't use any special access
(pretty sure a decision was made not to use/allow requestLegacyExternalStorage because it's 
"a short-term solution and only helpful in limited circumstances that it would only cause confusion")

Regards, ah

Dave

unread,
Aug 2, 2022, 3:00:00 PM8/2/22
to DroidScript
You are probably meeting problems with 'scoped storage' here.

You will need to ask the user for permission to write to any folder outside your app's sandbox.  Check out the 'Storage Access' sample to see how to do that.

Note: It might be working inside the DS IDE because you installed DS before you upgraded to Android 10 and DS is still using non-scoped storage.

Alan Hendry

unread,
Aug 2, 2022, 6:28:59 PM8/2/22
to DroidScript
Hi,
I believe that 2.51a1 is still in beta testing and "Replaced 'Sdcard Access' sample with 'Storage Access' sample"
(I presume that Sandbox means the folders you have access to without asking the user for additional access).
If I run that sample and choose Internal it prompts  Please give permission to your Documents folder.
then opens SanDisk SD card>DCIM>Camera (probably the last folder used in Files app) with no USE THIS FOLDER button
I can touch the hamburger in the top-left for Nokia 1.3 (presumably Internal), touch Documents, then USE THIS FOLDER
(prompted to Allow DroidScript to access files in Documents) and it pops up written hello
If I choose External then navigate to SanDisk SD card > Documents I can USE THIS FOLDER
It all seems a bit much to explain to a user and expect them to follow.
Regards, ah

Moreno B

unread,
Aug 26, 2023, 11:06:31 AM8/26/23
to DroidScript
As you suggested I used the 'Storage Access' sample and now I'm able to create a folder inside the Documents folder and then save a txt file.
The only problem I'm facing is that the "Append" mode of the app.WriteFile() function is not working properly in this case.
If I loop through a sequence of strings as the following, only the last one is saved:

for(let i=0;i<txtToExport.length;i++)
    {
        app.WriteFile( myFullPath, "title: "+txtToExport[i].title+"\n", "Append")
        app.WriteFile( myFullPath, "user: "+txtToExport[i].body_user+"\n", "Append")
        app.WriteFile( myFullPath, "password: "+txtToExport[i].body_pwd+"\n", "Append")
        app.WriteFile( myFullPath, "website: "+txtToExport[i].body_web+"\n", "Append")
        app.WriteFile( myFullPath, "\n", "Append")
    }

If I run the same code inside my app's sandbox it works perfectly and each string is stored on a new line of the same file.
Can you help me please?

Mannemmitt

unread,
Aug 26, 2023, 7:24:23 PM8/26/23
to DroidScript

Mannemmitt

unread,
Sep 2, 2023, 9:41:17 PM9/2/23
to DroidScript
I need access

Alan Hendry

unread,
Sep 11, 2023, 6:42:56 AM9/11/23
to DroidScript
HI,
What do you mean by "need access" in your last post?
In a previous post you said that your only remaining problem was with append.
I think that on Discord it was acknowledged that there is a problem with append, and a temporary solution would be to (read the file) append to a string and write.
Regards, ah
Reply all
Reply to author
Forward
0 new messages