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

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

Thanks very much for all your suggestions. However I have still not succeeded.

The blocks I've been using for my experiments are along these lines (the app name is FE3):

TwoBlocksFromFE3

If I put test.txt in TextBox1_SaveFileName, what should I put in TextBox2_ShareFileName?

(If the filename in TextBox1 is prefaced by / (/test.txt) then there is no problem: /sdcard/test.txt in TextBox2 works and I can share the file. But apparently (http://appinventor.mit.edu/blogs/evan/2020/08/08/file-path-updates-android-10) this will no longer be allowed in later versions of Android.)

The experiments described below are done on Android 8.1.0 but I think my experiments with Android 10 were similar.

I've tried putting the following in TextBox2:

test.txt

/storage/emulated/0/Android/data/appinventor.ai_mickofemsworth.FE3/files/test.txt
(This is based on Anke's ASD extension.)

file:///emulated/0/Android/data/appinventor.ai_mickofemsworth.FE3/files/test.txt

These all resulted in file not found errors.

This is based on the assumption that the ASD is the same as the private directory. Taifun says this is not so, so I found a path for the private directory somewhere (one of Anke's posts?):
/data/user/0/appinventor.ai_mickofemsworth.FE3/files/test.txt
which resulted in a different error: "failed to find configured root that contains .../data/data/app...

I also tried putting
storage/emulated/0/Android/data/appinventor.ai_mickofemsworth.FE3/files/test.txt
in TextBox1_SaveFile - this produced a file could not be created error.

Any ideas? Thanks!

it seems you didn't read this discussion

I'm slightly confused about which discussion you are referring to. One of your posts is about saving a file called /test.txt or /a.txt. This isn't a problem because I can share using /sdcard/test.txt. The problem is when there's no / so the file is stored in the app's private directory.

you might want to read starting from here again

Taifun