Android Question Get file from server and send to email automatically

Makumbi

Well-Known Member
Licensed User
i have this file here which i want to automatically send to my email please help

B4X:
http://kccug.com/KabojjaApp/workold/P5WORK.PDF



B4X:
Dim FileName As String = "b4a.png"
    'copy the shared file to the shared folder
    File.Copy(File.DirAssets, FileName, Starter.Provider.SharedFolder, FileName)
    Dim email As Email
    email.To.Add("[email protected]")
    email.Subject = "subject"
    email.Attachments.Add(Starter.Provider.GetFileUri(FileName))
    email.Attachments.Add(Starter.Provider.GetFileUri(FileName)) 'second attachment
    Dim in As Intent = email.GetIntent
    in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
    StartActivity(in)
 

Peter Simpson

Expert
Licensed User
Longtime User
Oh yes, I forgot about your second question.

 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Oh yes, I forgot about your second question.


i use this file to download but this downloads and save on the phone

B4X:
DownloadAndSaveFileP1("http://kccug.com/KabojjaApp/workold/P1WORK.PDF")
Sub DownloadAndSaveFileP1 (Link As String)
 
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Link)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
      
        Dim out As OutputStream = File.OpenOutput(File.DirInternal, "P1WORK.PDF", False)
        File.Copy2(j.GetInputStream, out)
        out.Close
              
        Dim rp As RuntimePermissions
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
            File.Copy(File.DirInternal, "P1WORK.PDF", File.DirRootExternal, "Download/P1WORK.PDF")
            Dim FilePath As String = File.Combine(File.DirRootExternal, "Download/P1WORK.PDF")
            
            Dim Phone As Phone
            If Phone.SdkVersion <= 18 Then           ' min - 4.3.1
                Dim i As Intent
                i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", "file://" & FilePath)
                Phone.SendBroadcastIntent(i)
            Else
                Dim ctxt As JavaObject
                ctxt.InitializeContext
                Dim MediaScannerConnection As JavaObject
                MediaScannerConnection.InitializeStatic("android.media.MediaScannerConnection")
                Dim interface As Object = MediaScannerConnection.CreateEventFromUI("android.media.MediaScannerConnection.OnScanCompletedListener", "ScanCompleted", _
                   Null)
                MediaScannerConnection.RunMethod("scanFile", Array(ctxt, Array As String(FilePath), Array As String("image/pdf"), interface))
            End If
        End If
      
    End If
    j.Release
    MsgboxAsync("The downloaded work has been placed in Downloads of Adobe acrobat reader. Please Install adobe acrobat reader incase it is not yet installed on your phone thank you. And Check in Adobe click files. ","Homework Downloaded")
    ProgressDialogHide
    'Sleep(0)'saveimag
End Sub

this what iam using to download and save but i wanted to download and automatically send to email
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Well, once you have downloaded the file and used j.released, just run your next routine which will be your send email routine that I posted a link to in Post #2.

 
Upvote 0
Top