I'm trying to share a page rendered by webview as an image.
The ideal would be as a PDF, but as I had difficulty getting this, I'm saving it as an image. This already solves my problem, since the pages are not large.
It turns out that the page contains images, and the resulting image from the generated html is too long, as shown below, and the images are not generated.
Below is a link where you can view an example page that is generated in the code.
https://safetymov1.hospedagemdesites.ws/sistema/app/view4b4x.php
This is my code:
It depends on Fileprovider library.
The layout used is attached, just in case, but it's just the webview and a "share" button.
Any help will be welcome. Thanks.
The ideal would be as a PDF, but as I had difficulty getting this, I'm saving it as an image. This already solves my problem, since the pages are not large.
It turns out that the page contains images, and the resulting image from the generated html is too long, as shown below, and the images are not generated.
Below is a link where you can view an example page that is generated in the code.
https://safetymov1.hospedagemdesites.ws/sistema/app/view4b4x.php
This is my code:
B4X:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private WebView1 As WebView
Private xarq As String
Private Provider As FileProvider
End Sub
'You can add more parameters here.
Public Sub Initialize As Object
Return Me
End Sub
Public Sub Mostrar(peca As String)
Provider.Initialize
xarq = peca & ".png"
WebView1.LoadUrl("http://safetymov1.hospedagemdesites.ws/sistema/app/view.php?peca=" & peca)
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("inspecao")
End Sub
Private Sub B4XPage_Disappear
' B4XPages.ShowPage("Mainpage")
End Sub
Private Sub btnVoltar_Click
B4XPages.ShowPage("Mainpage")
End Sub
Private Sub btnSalvar_Click
Dim bmp As Bitmap
bmp = WebView1.CaptureBitmap
If bmp <> Null Then
Dim OutputStream As OutputStream
OutputStream = File.OpenOutput(Provider.SharedFolder, xarq, False)
bmp.WriteToStream(OutputStream, 100, "PNG")
OutputStream.Close
shareFile
End If
End Sub
Sub shareFile
Dim in As Intent
in.Initialize(in.ACTION_SEND, "")
in.SetType("image/png")
in.PutExtra("android.intent.extra.STREAM", Provider.GetFileUri(xarq))
in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
StartActivity(in)
End Sub
It depends on Fileprovider library.
The layout used is attached, just in case, but it's just the webview and a "share" button.
Any help will be welcome. Thanks.