Spanish ¿Cómo enviar imagen a WhatsApp?

Edgardo PuntoCom

Member
Licensed User
Yo estoy usando INTENT ID v1.50. Me funciona bien en Android 7 e inferiores, pero en Android 8 no me funciona.

La aplicación guarda una porción de la pantalla como imagen y después envío ese archivo a WhatsApp, Messenger, etc.

B4X:
Sub p120_Click'COMPARTIR POR WHATSAPP
            If cuadros = 0 Then
                ToastMessageShow(ley14, False)
                Return
            End If
            p112_Click
            Dim b As Bitmap
            Dim c As Canvas
            b.InitializeMutable(p200.Width, p200.Height) ' Initialize mutable bitmap to contain size of aView ...
            c.Initialize2(b) ' Get bitmap canvas ...
            Dim args(1) As Object
            Dim types(1) As String
            Dim r As Reflector
            r.Target = c
            args(0) = r.GetField("canvas") ' Get android.graphics.Canvas field ...
            types(0) = "android.graphics.Canvas"
            ' Draw aView content onto the bitmap canvas ...
            r.Target = p200
            r.RunMethod4("draw", args, types)
            If File.Exists(File.DirRootExternal, "superMEME") = True Then
            Else
                File.MakeDir(File.DirRootExternal, "superMEME")
            End If
            
            Dim rp As RuntimePermissions
            rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
            Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
            If Result Then
                Dim out As OutputStream
                out = File.OpenOutput(File.DirRootExternal & "/superMEME/", "temp321123.jpg", False)
                b.WriteToStream(out, 100, "JPEG")
                out.Close
                Dim compartir As INTENTID
                If compartir.IsInitialized = False Then compartir.Initialize
                inter
                compartir.ShareImage(File.DirRootExternal & "/superMEME/", "temp321123.jpg",True)
                'access here
            Else
                'no permission
            End If

End Sub
 

Edgardo PuntoCom

Member
Licensed User
Eso no me sirvió.

Pero me recomendaron con esto https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/ dice Erel se debe usar FileProvider

Agregue la clase. Edite el Starter. Edite el manifiesto. Tal y como lo indica.

Para enviar la imagen a WathsApp y demás cambie esto:
B4X:
                Dim out As OutputStream

                out = File.OpenOutput(File.DirRootExternal & "/superMEME/", "temp321123.jpg", False)
                b.WriteToStream(out, 100, "JPEG")
                out.Close
                Dim compartir As INTENTID
                If compartir.IsInitialized = False Then compartir.Initialize
                inter
                compartir.ShareImage(File.DirRootExternal & "/superMEME/", "temp321123.jpg",True)

por esto:
B4X:
        Dim out As OutputStream

        out = File.OpenOutput(File.DirRootExternal & "/superMEME/", "CreadoConSuperMEME.jpg", False)
        b.WriteToStream(out, 100, "JPEG")
        out.Close
        
        Dim FileName As String = "CreadoConSuperMEME.jpg"
        File.Copy(File.DirRootExternal & "/superMEME/", "CreadoConSuperMEME.jpg", Starter.Provider.SharedFolder, FileName)
        Dim in As Intent
        in.Initialize(in.ACTION_SEND, "")
        in.SetType("image/jpg")
        in.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri(FileName))
        in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
        in.WrapAsIntentChooser("Select")
        StartActivity(in)
Con esto ya funciona en Android 7 y 8.
 
Top