Can an AI2 app create a non application specific folder

I’m about to publish an app that requires a folder to be created on the SD card before it can be run. The folder will be read to and written from using AI2 and should also be accessible to the user to edit with tools of their choice.

At present I’m suggesting to users that they create the folder manually but is it possible to create a specific folder under program control as part of an AI2 app?

Many thanks for any advice, regards, Peter

Hi,

I think you should take a look at the file extension from @Taifun. You can do a lot of file operations with it.

https://puravidaapps.com/file.php

2 Likes

Hi Peter,

I did visit the original topic that was raised a few years ago and have had some good experiences with the Taifun File extension, mainly using it for diagnostics.

Taifun mentions that the function that copies from file to file will on some phones create a folder if you copy from a file to a folder that doesn’t exist. That sounds useful but wouldn’t make installation of the app any easier as the user would have to have created a folder anyway.

The extension also has an application specific folder creation function but it didn’t work on my phone. I suspect its a security issue with Android Go perhaps disallowing such instructions. Also the application specific folder doesn’t allow the user ready access to the file using a PC, which is a feature I’d like to keep.

I suspect the answer to my question is the same as the answer to a similar question by another user several years ago that there is no function that will create a folder on the SD card. But I thought it worth asking again. Its not essential as I can just ask people using my app to set up the file manually, but I should only do that if its not possible for the file to be installed automatically.

Thanks for the response though, Peter

... but it didn't work on my phone.

What does not work? Did you get an error message?

Try this:


This should work also with Android 10.

Taifun indicates a developer can use the Canvas control components to create a directory.
See this Forum discussion https://groups.google.com/forum/#!category-topic/mitappinventortest/3TK_RvyAOEs and review Taifun’s Dec 27 post.

Will it work with an external sDCard? Sorry I do not know. Why not try his suggested method Peter?

Actually, the discussion is in response to your question you made on the Google MIT Forum.

Of course, you can create a folder on the external storage (internal) SD card, but not on the removable SD card (micro SD card). This is only readable.

See also here:

1 Like

is your question about the internal sdcard or the external (removable) sdcard?

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

Hi All,

Steve
I had studied the links and the work-around you referenced. Its a discussion that seems to be spread over two or three topics and some solutions worked for some developers but none consistently worked for all developers except for a method that accessed the root directory of the phone, which could be a security issue in an app for the general public. See for example: https://groups.google.com/forum/#!msg/mitappinventortest/WKL-arLP6Yk/XEs8h2yd1yEJ which is linked to the discussion you mentioned.

The canvas work around that Taifun describes looks very useful but requires setting up an additional button, text box and canvas so it might complicate my app’s operation and display. Would it be universally applicable to all Android phones?

Anke
Thank you for the example. I may have misunderstood how the ‘create application specific directory’ and ‘application specific directory’ methods work. I’ll report back any errors after I’ve tried some of the tests you show but I’m going to avoid the Taifun1.copy function. The PuraVid web page suggests that the Taifun1.copy function by itself can create a folder. However, it requires an app user to have already created a dummy file so unfortunately it doesn’t simplify the user’s installation task.

Anke and Taifun
My apologies I wasn’t more specific. I meant the internal SD card as neither of my phones has an extenal SD card slot. If I manually create a folder such as ‘PushTo’ the phone’s file manager gives its address as Internal/MyFolder and I can read and write a file such as NewCal.txt to files in that folder without any problem. .

image

When the user first uses my app its desirable but not essential for the folder ‘PushTo’ to be automatically created and not interfered with on subsequent uses of the app. If that’s not practical then I’ll ask the user to install the folder manually. The reference I’ve been using for file management is: http://ai2.appinventor.mit.edu/reference/components/storage.html#File and for example it states: “Prefix the filename with / to read from a specific file on the SD card. for instance /myFile.txt will read the file /sdcard/myFile.txt.”

Many thanks for your thoughts on this, Peter

Hi Anke,

Your reference to the FileTools extension seems to have exactly what I’m looking for and the reference on directory addresses is also very informative. I’ll try the method FileTools1.create directory as my first priority and let you know how it worked.

Thanks again, Peter

Where exactly is the problem?
If you don’t want to create an app-specific folder, which would actually be the best solution, try this to create a non-app-specific folder, which need WRITE permission:

createDirectory.aia (55.5 KB)

1 Like

The data base files the app uses are intended to be modifiable either by using the app or with programs such as Excel. As some star databases may include up to one or two hundred thousand records so the Excel option run on a lap top computer could be very useful. Would an app-specific folder be accessible using a laptop computer and a USB link?

PS Anke,

Your aia is most helpful and I’ll look forward to trying it out this afternoon and learning how the request for permission operates.

Many thanks, Peter

Yes of course.

which means, you could use the file extension and save a file in a directory of your choice... and btw. in case the directory does not exist, the directory will be created automatically... similar to the example @Anke provided, but with less blocks, because you do not need to create any directory...

Taifun

2 Likes

Hi Anke and Taifun,

Taifun’s CreateApplicationSpecificDirectory works now I understand the directory structure and take into account that the app specific folder and its files are hidden and inaccessible when the app runs autonomously. The only time the folder was visible and accessible by programs other than the app was for development purposes when it was operating through the AI companion. This is consistent with the app specific folder’s role to prevent non app programs from interfering with the app’s files.
image

Taifuns suggestion that a folder will automatically be created if its missing in a save file operation didn’t work for me see image below. As expected the TaifunFile1.copy method did work when Anke used it to write a folder to the AppSpecificFolder location. However, as already discussed this isn’t appropriate for my application.
image

Anke’s demonstration of the Filetools.createDirectory method worked and is an effective solution to my issue. I’d like to understand the permissions blocks better because it looks as if the permission is bypassed by a second createDirectory block and when I disabled all the permission functions it made no difference, I still received the standard permission request that occurs when I install a new app and which is essential for the security of the user. I’ve tried this on only one phone so its likely that the request for permsision may be useful on other phones, but I’d like to understand it better.
image

So thank you both for solving my problem and if anyone has any references that explain the permission method I’d be keen to read them.

Peter

You have to use a slash "/", not a back slash "\"

1 Like

You might want to "like" an answer and especially click “Solution” if your question has been answered.
Thanks, Anke

1 Like

Thanks Anke for picking up my mis-typing. When I tried the correct forward slash it still didn’t work and came back with the Error2103:The file/storage/emulated/0/TestFolder/TestFile.txt could not be created. So I’ll click your aia post as the solution and check the answers I particularly liked.

image

@ewpatton the file component should be able to create a directory in case it does not exists while using the SaveFile method... I consider this a bug... what do you think?

Taifun

1 Like

Yes, that has never worked before. I used your TaifunFile extension for this and copied an empty dummy file from the assets into the new folder to create this directory beforehand.