Android Question Share Audio Provider

Marcio Costa

New Member
Licensed User
I have an application that shares audios, however, I need to upgrade it to sdk 27 using the provider

This is my code
B4X:
Sub ShareAudioOn_Intent(folder As String,audiofile As String,intent As String)
    File.Copy(folder,audiofile,sFolder,audiofile)
   
    PuxaIntent_Audios(intent,sFolder,audiofile)
   
    If sIntent.Contains(intent) Then
        Try
            Dim u As Uri
            u.Parse("file://" & File.Combine(sFolder,audiofile))
            Dim i As Intent
            i.Initialize(i.ACTION_SEND,"")
            i.SetType("audio/*")
            i.SetComponent(sIntent)
            i.PutExtra("android.intent.extra.STREAM",u)
            StartActivity(i)
        Catch
            Log("Error: Intent Error "&intent)
        End Try
       
    Else
        Log("Not Found: "&intent)
    End If
End Sub

from what I understood from Erel, I would have to upgrade with CreateFileProviderUri, but could not, could anyone help me in this?

Erel's code
B4X:
Sub Button1_Click
    'copy the file to the shared folder
    File.Copy(File.DirAssets, "1.bal", Starter.shared, "1.bal")
    Dim in As Intent
    in.Initialize(in.ACTION_SEND, "")
    in.SetType("text/plain") 'it is not related to the file itself.
    in.PutExtra("android.intent.extra.STREAM",  CreateFileProviderUri(Starter.shared, "1.bal"))
    in.Flags = 1
    StartActivity(in)
End Sub

Sub CreateFileProviderUri (Dir As String, FileName As String) As Object
    Dim FileProvider As JavaObject
    Dim context As JavaObject
    context.InitializeContext
    FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
    Dim f As JavaObject
    f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
    Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
End Sub
 
Top