Android Question [SOLVED] File provider - question

TomKluz

Active Member
Licensed User
I am studing File Provider example because I would like to share files between apps or eventually send email with attached file.

Partial code from FileProvider example:
Private Sub btnSendEmail_Click
    Dim FileName As String = "b4a.png"
    'copy the shared file to the shared folder
    File.Copy(File.DirAssets, FileName, Provider.SharedFolder, FileName)
    Dim email As Email
    email.To.Add("aaa@bbb.com")
    email.Subject = "subject"
    email.Attachments.Add(Provider.GetFileUri(FileName))
    email.Attachments.Add(Provider.GetFileUri(FileName)) 'second attachment
    Dim in As Intent = email.GetIntent
    in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
    StartActivity(in)
End Sub

My question is about SharedFoulder. Actually I cant find it in my phone. Where it is ?
Thanks in advance.
 

TomKluz

Active Member
Licensed User
Try
B4X:
Log(Provider.SharedFolder)
?
I have already did it. The result is:
/data/user/0/b4a.example/files/shared
There are files which shouldn't be there. Thay was created before I have bought this phone (only purpose was to test Android 14).
As I mentioned I cant find such directory on my phone.
Maybe this is virtual space connected to google account ? I got lost.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have already did it. The result is:
/data/user/0/b4a.example/files/shared
There are files which shouldn't be there. Thay was created before I have bought this phone (only purpose was to test Android 14).
As I mentioned I cant find such directory on my phone.
Maybe this is virtual space connected to google account ? I got lost.
They can only be there if the previous owner had B4A, given the b4x.example folder, and you never installed an app with that name, which is unlikely.

Can't delete them?
 
Upvote 0

TomKluz

Active Member
Licensed User
Can't delete them?
Yes, I can't delete them.
I have installed b4x.example many times before on another devices.
So, thay are not on my phone ?

Yes. it is Google disk. I have sent email to myself and it seem to be a true. I have found this mysterious disk on google account. So far I have had no idea that it exists and in which way files are stored there. I've never consciously done it.
Sorry for wasing your time.
 
Last edited:
Upvote 0

TomKluz

Active Member
Licensed User
Actually I am trying to only to send file to google disk and then find it by googe web browser.
I have no foults in the log.
The result of:
B4A:
Log(Provider.SharedFolder)
is:
/data/user/0/DemoEmail/files/shared
I can't find this directory on google disk. Do you have an idea where it is ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I can't find this directory on google disk
It is a path on your device from which you can share files to google drive. The receiver (google drive app) need to copy the file and put it into your drive disc after you shared it with the driveapp.

As you did not uploaded a example project we can only guess what you are doing (or not) and how.
 
Upvote 0

TomKluz

Active Member
Licensed User
As you did not uploaded a example project we can only guess what you are doing (or not) and how.
Thank you for your note:

This is my code just copyd from FileProvider example:

B4A:
Sub SendEmail
   
    Log(Filename)
   
    Dim Provider As FileProvider
   
    Provider.Initialize
   
    'Dim Filename As String = "b4a.png"
    'copy the shared file to the shared folder
    Log(Provider.SharedFolder)

    'File.Copy(File.DirAssets, Filename, Provider.SharedFolder, Filename)
    File.Copy(MyFolder, Filename, Provider.SharedFolder, Filename)
   
    Log ("File copyed")
           
'    Dim email As Email
'    'email.To.Add("aaa@bbb.com")
'    email.Attachments.Add(Filename)
'    'email.Attachments.Add(Provider.GetFileUri(FileName)) 'second attachment
'    Dim in As Intent = email.GetIntent
'    in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
'    StartActivity(in)
End Sub

As I mentioned I have no foults in the logs.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
What do you mean ? Should I post entire project ?
DonManfred said, the code at post#10 just does copy file to SharedFolder, not share anything at all. you'd better upload an example project.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What do you mean ? Should I post entire project ?
No. Learning on how Sharing files work with the use of FileProvider.

See this Tutorial:
 
Upvote 0

TomKluz

Active Member
Licensed User
I realized that it works, but current activity (my app) is on the top, target activity (inn) not appears on a display.
I have to leave my app (or eventually go back ) and then I can see sharing panel. After clicking Gmail everything goes well. Email is sent with succes.
The question is:
Is it possible to force sharing panel to appear and eventually start directly email creator not a sharing panel ?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
As so far, we don't know how you did sharing and which activity you started.
 
Upvote 0

TomKluz

Active Member
Licensed User
As so far, we don't know how you did sharing and which activity you started.
Hi. My intention is to send email with the attachment. Attachment is a pdf file.. It works but target activity ( in = email.intent) don't want to come up to be visible when invoked. I have to leave my app or at least to go back to see result.
My last question was: Is it any way to force activity responsible for sending emails to be visible immediately when invoked by StartActivity)(in) ?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Now I got your intention. if you would like to sent a pdf to your mailbox in silence, you can use smtp to do that instead of using intent.
 
Last edited:
Upvote 0

TomKluz

Active Member
Licensed User
Now I got your intention. if you would like to sent a pdf to your mailbox in silence, you can use smtp to do that instead of using intent.
Hi,
Yes. I can use SMTP to send mail but it will be OK when basic app will be only for myself. In my case app is made for customers and will be hard to use individual settings of different email accounts (channel, servers, password etc) .
The original purpose is to make this pdf availabe for the user to send it somewhere or just to print. So far I was using a shortcut to the internal folder containing all reports (pdf files) and my customers are sending emails independly. Recently (Android 14) when acces to this space is limited I have to find some solution.
Any idea is welcomed.
Thank you for taking care of my problem.
 
Upvote 0
Top