Android Question Intent error

Espinosa4

Active Member
Licensed User
Longtime User
I am trying to send a file by email or bluetooth or something like that. This code was correct but now doesnt work.

Intent:
Sub Envio_Click
    Dim u As Uri
    u.Parse("file://" & File.Combine(File.DirDefaultExternal,"l4pro.sql"))
    Dim i As Intent
    i.Initialize(i.ACTION_SEND, "")
    i.SetType("*/*")
    i.PutExtra("android.intent.extra.STREAM",u)
    StartActivity(i)
End Sub

I attach a pic with the error message.

Could you help me please?
Thank you very much indeed in advance.
IMG_20201215_191310.jpg
 

edgar_ortiz

Active Member
Licensed User
Longtime User
Upvote 0

Espinosa4

Active Member
Licensed User
Longtime User
1. Large images make the post unreadable.
2. The suggested link above is irrelevant.
3. Any code with File.DirDefaultExternal = broken code.
4. You should use FileProvider to share files.
Hi Erel,
Sorry to bother you, but the fileprovider still doens't work for me.




B4X:
Public Sub GetFileUri (FileName As String) As Object
 
    If UseFileProvider = False Then
        Dim uri As JavaObject
        Return uri.InitializeStatic("android.net.Uri").RunMethod("parse", Array("file://" & File.Combine(Main.safedefaultexternal, FileName)))
    Else
        Dim f As JavaObject
        f.InitializeNewInstance("java.io.File", Array(Main.safedefaultexternal, FileName))
        Dim fp As JavaObject
        Dim context As JavaObject
        context.InitializeContext
        fp.InitializeStatic("android.support.v4.content.FileProvider")
        Return fp.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
    End If
End Sub

The program crashes when it arrives to the follow line: Return fp.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f)) and it doesn't return any error.

And here my code:
B4X:
Sub Envio_Click
    Dim FileName As String = "l4pro.sql"
    'copy the shared file to the shared folder
    File.Copy(safedefaultexternal, FileName, Starter.Provider.SharedFolder, FileName)
    Dim email As Email
    email.To.Add("[email protected]")
    email.Subject = "subject"
    email.Body = "This is a test" 'This is the added code
    email.Attachments.Add(Starter.Provider.GetFileUri(FileName))
    email.Attachments.Add(Starter.Provider.GetFileUri(FileName)) 'second attachment
    Dim in As Intent = email.GetIntent
    in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
    StartActivity(in)
End Sub

Could you help me, please?
 
Upvote 0
Top