In Erel's example in the tutorial here the files should be copied to a shared folder to make them available for further use and then use the FileProvider.
This is where my problem starts, since I can't bring the puzzle together to make use of the FileProvider:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
AddApplicationText(
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="$PACKAGE$.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
)
CreateResource(xml, provider_paths,
<external-files-path name="name" path="shared" />
)
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private images As List = Array("B4A.png", "B4i.png", "B4J.png", "B4R.png")
Private sharedFolder As String
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
sharedFolder = Starter.rp.GetSafeDirDefaultExternal("shared")
End Sub
Sub Activity_Resume
Dim i As Intent
i.Initialize("android.intent.action.SEND_MULTIPLE", "")
i.SetType("image/jpeg")
Dim Uris As List
Uris.Initialize
For Each image As String In images
File.Copy(File.DirAssets, image, sharedFolder, image)
' ?? SetFileUri(res, image)
' Dim u As Uri
' u.Parse("file://" & File.Combine(Starter.strSharedFolder, image) )
' Uris.Add(u)
Next
Dim jo As JavaObject = i
jo.RunMethod("putParcelableArrayListExtra", Array As Object("android.intent.extra.STREAM", Uris))
StartActivity(i)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub SetFileUri(In As Intent, FileName As String)
' From here--> https://www.b4x.com/android/forum/threads/sharing-files-from-your-app-with-file-provider.70458/#content
Dim context As JavaObject
context.InitializeContext
Dim FileProvider As JavaObject
FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
Dim f As JavaObject
f.InitializeNewInstance("java.io.File", Array(sharedFolder, FileName))
Dim jo As JavaObject = In
jo.RunMethod("setData", Array(FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))))
In.Flags = 0x00000001
End Sub
Edit:
As always. Due to Erels little push there is no problem since post #4 for API up to 23.
Edit:
For API 24 it is possible to share multiple images as described in post #9.
Last edited: