Android Question content choose

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime User
Hello , I need help . I need to choose an image from the gallery , but achieves select the DIR and filename does not work or is not the right to attach it to an email. as I have to do ?
part of code.
When you send email , it indicates that you can not attach an empty file

B4X:
sub globals
Dim filename1 As String
Dim dir1 As String
Dim Galeria As ContentChooser
end sub

Sub Botfoto_Click
      Galeria.Initialize("galeria")

      Galeria.Show("image/*","Seleccione Imagen:")
   
  
End Sub

Sub Galeria_Result (Success As Boolean, Dir As String, FileName As String)
 
    If Success  Then
    
    Msgbox(FileName,"") ' Directorio de la imagen
    Msgbox(Dir,"") ' Nombre del fichero
  
filename1 = fileName
  dir1 = Dir

   Else
   Return
   End If
  
End Sub


Sub enviar_mail ()
  
    Dim mensaje As Email
  
     
    mensaje.To.Add("[email protected]")
    mensaje.Subject =evento_electrico & evento_informacion & evento_telefonico & evento_internet &  " " & Editsuministro.Text
    mensaje.Body = Editobs.Text
  
    If File.Exists(dir1,filename1) = True Then
    mensaje.Attachments.Add(filename1)
    End If
    StartActivity(mensaje.GetIntent)
  
    
End Sub
 

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime User
Perfect! thank you! I'm happy I sold my first application to a company, and with it the end.

Add this code to step erel
B4X:
Sub GetPathFromContentResult(UriString As String) As String
  If UriString.StartsWith("/") Then Return UriString 'If the user used a file manager to choose the image
  Dim Cursor1 As Cursor
  Dim Uri1 As Uri
  Dim Proj() As String = Array As String("_data")
  Dim cr As ContentResolver
  cr.Initialize("")
  If UriString.StartsWith("content://com.android.providers.media.documents") Then
  Dim i As Int = UriString.IndexOf("%3A")
  Dim id As String = UriString.SubString(i + 3)
  Uri1.Parse("content://media/external/images/media")
  Cursor1 = cr.Query(Uri1, Proj, "_id = ?", Array As String(id), "")
  Else
  Uri1.Parse(UriString)
  Cursor1 = cr.Query(Uri1, Proj, "", Null, "")
  End If
  Cursor1.Position = 0
  Dim res As String
  res = Cursor1.GetString("_data")
  Cursor1.Close
  Return res
End Sub

and then modify the code that attach to mail for

B4X:
mensaje.Attachments.Add(GetPathFromContentResult(archivo))

and sub

B4X:
Sub Botfoto_Click
     Galeria.Initialize("galeria")

      Galeria.Show("image/*","Seleccione Imagen:")
    
  
End Sub


Sub Galeria_Result (Success As Boolean, Dir As String, FileName As String)
  
     If Success  Then
   ' ya puedes emplearlo en cualquier sitio
 

  
    Msgbox(FileName,"") ' Directorio de la imagen
    Msgbox(Dir,"") ' Nombre del fichero
    archivo = FileName
  
  
   Else
   Return
   End If
  
End Sub
 
Upvote 0
Top