How can I share files in my app's private data directory?

If I save a filename without a slash (file1) what should the file path be when using ShareFile? Delete and ReadFrom both work fine with just the file name, but not ShareFile.

The ExternalStorage block below works fine, but what should X be in the PrivateAppStorage block? I've tried everything I can think of but without success. (I am using Moto G5 with Android 8.1.0 and a Samsung A50 with Android 10 and legacy mode switched on.)

image

I first had this problem a year ago, but gave up trying to make ShareFile work because it was easy to use other apps like Google Drive to share files. Now when Android 10 and 11 kick in this won't work, so the problem is now more urgent (http://appinventor.mit.edu.ezproxy.canberra.edu.au/blogs/evan/2020/08/08/file-path-updates-android-10).

I have a couple of very useful apps which depend on saving and sharing files and am getting very frustrated. Please help!

Many thanks ... Michael

you might want to experiment using this extension

also @Anke already did a lot of experiments, you can find them here Search results for '@Anke ASD' - MIT App Inventor Community and here Search results for '@Anke private ' - MIT App Inventor Community

Taifun


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

1 Like

Hi

Many thanks for your help. I'll look at the detailed links later, but I can't get your suggested path to work on either phone (Android 8.10 and 10). I've tried substituting the following for X in the second block above:

/storage/emulated/0/Android/data/FE/files/file1
and
/storage/emulated/0/Android/data/FE/file1
(The AppName on the Designer screen is FE so the apk file is FE.apk. In each case I get a file not found error.)

Any suggestions?

Thanks

Michael

.... the two paths above should end with .txt for consistency with the saved file of course

I've now downloaded Anke's extension to get the ASD for my app (called FE2). This is /storage/emulated/0/Android/data/appinventor.ai_mickofemsworth.FE2/files . I then tried the path /storage/emulated/0/Android/data/appinventor.ai_mickofemsworth.FE2/files/filename in the Sharefile block to share a file I saved as filename. Unfortunately I got the same file not found error. I also tried saving the file using the long path which resulted in a file could not be created error. I'm probably doing something stupid but I haven't a clue what. Any suggestions??

Many thanks.

Post your (relevant) blocks.

try this path
file:///emulated/0/Android/data/appinventor.ai_mickofemsworth.FE2/files/filename

The Save block works (I can read the file) but the Sharefile block produces a file not found error.

Thanks but I'm afraid it doesn't work - another file not found error.

you are storing the file to the private app directory but you are trying to share it from the application specific directory, which is different
you might want to save the file to the ASD, you can use a method rom @Anke's extension for this...

Taifun


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

1 Like

see also

Taifun

1 Like

Yes,

  1. The Sharing component cannot share a file from the Private dir.
  2. You try to share it from the ASD as @Taifun said. So do what Taifun suggest:

There is a bug with the Sharing component. → @ewpatton
It needs the absolute path, but the File.AfterFileSaved event returns the relative path.

Therefore try this:

this code runs well on android 10! Legacy mode to be unchecked

Yes, but not on devices with Android < 10, as I have shown.
So keep using my blocks until the bug is fixed.

why using these blocks I can not share the file ?

How about taking a close look at my blocks?

Thanks for this Taifun. I have tried saving the file to the path given by Anke's ASD extension but this doesn't work. You say I can use a method from @Anke's extension for this, but I can't find it - please can you tell me where it is?

What does not work?
Show your blocks.

The blocks was correct, but file1 was in legacy mode, when unchecked no problem to find file for sharing