Android Question Using FileProvider to upload files but...

ilan

Expert
Licensed User
Longtime User
hi

i have uploaded my old app to use FileProvider to upload or share files (as erel suggested)

my problem is that i am using backup files to backup all my data and allow to upload to google drive or share with any other option like email,..

i also save the file in the shared folder (shared = rp.GetSafeDirDefaultExternal("shared")) to let the user restore all his data to a previous point by loading an older backup.

anyway, everything is working fine my only problem is that when the user has deleted the app accidentally the all files in that shared folder are deleted. what possibilities do i have now? should i go back to "File.DirDefaultExternal" ??

my second question is. i used this code in the past to show an image with the default gallery viewer

B4X:
'           
           Dim i As Intent
           i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(Starter.shared, uri))
           i.SetType("image/*")
           StartActivity(i)

but now its not working anymore, how can i use FileProvider for this?

i tried this but i get a message that the file was not found. but the file is there i even get true if i check if the file exists.

B4X:
           Dim i As Intent
           i.Initialize(i.ACTION_VIEW, CreateFileProviderUri(Starter.shared, uri))
           i.SetType("image/*") 'it is not related to the file itself.
           StartActivity(i)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
should i go back to "File.DirDefaultExternal" ??
It will not help. They point to the same path.

You can use a custom folder under File.DirRootExternal. The folder will not be deleted. It requires acquiring the storage permission.

but now its not working anymore, how can i use FileProvider for this?
What is uri? I guess that the file was not copied to the correct location.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
You can use a custom folder under File.DirRootExternal

I did it like that before but now i target sdk26 so i guess i will need to use runtime permission right?

What is uri? I guess that the file was not copied to the correct location.

No the path is correct it is working with target sdk 19. Now i use target sdk 26 so maybe i need to use runtime permission for that?

Uri points to the shared folder (safe folder) as in your example code of file provider.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I did it like that before but now i target sdk26 so i guess i will need to use runtime permission right?
Yes.

Now i use target sdk 26 so maybe i need to use runtime permission for that?

If you are only using GetSafeDirDefaultExternal then you don't need any permission.
 
Upvote 0
Top