Android Question shared Folder - deleting files after viewing

Andromeda

Member
Licensed User
Longtime User
Hello, when i copy a file to the shared folder with the FileProviderClass
i can access the file with an extern app like excel.
But Excel cant delete them afterwards. (only read allowed)

B4X:
    Dim FileName As String = "Test.csv"
    File.Copy(DirDefaultExternal, FileName, Main.Provider.SharedFolder, FileName)
    Dim in As Intent
    in.Initialize(in.ACTION_VIEW, "")
    Main.Provider.SetFileUriAsIntentData(in, FileName)
    'Type must be set after calling SetFileUriAsIntentData
    in.SetType("application/csv")
    StartActivity(in)


How can i get rid of those files after excel is closed?
I dont want to mess with my phonememory.
 

JohnC

Expert
Licensed User
Longtime User
There is no practical way to detect when the user is done using a file that your app shared.

One way to deal with this situation is to delete any files that were shared *the next time your app is run*.

For example, let say your app shares the file "main.txt" to another app, which the user then uses the other app to work with the shared file. Now, when the user runs your app again, it is usually safe to assume that the user no longer is viewing the previous "main.txt" file.

So, in the startup code of your app, you can delete the previously shared file "main.txt" (or if the shared files always end in .txt, you can do a delete of *.txt so you wont have to keep track of the file name of each file your app shared).

This way all previously shared files will be deleted each time your app is run, so you phone memory will not keep filling up.
 
Upvote 0

Andromeda

Member
Licensed User
Longtime User
Excel cant delete this file even with this Grant_access

Main.Provider.SetFileUriAsIntentData(in, FileName)
'Type must be set after calling SetFileUriAsIntentData
in.SetType("application/vnd.ms-excel")
in.Flags = Bit.Or(in.Flags, 2) 'FLAG_GRANT_WRITE_URI_PERMISSION
StartActivity(in)
 
Upvote 0
Top