Android Question error while sending file to email

Makumbi

Well-Known Member
Licensed User
here is the error i got

when the i reach here

B4X:
  File.Copy(File.DirAssets, FilePath , Starter.Provider.SharedFolder, FilePath )
B4X:
Copying updated assets files (1)
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
0
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
0782911364
** Service (httputils2service) Start **
Account: 19-07561
Name: MAKUMBI TARIQ AZIZI
Category: Active
Froms: /Date(1560891600000)/
Tos: /Date(1590354000000)/
06/19/2019
19/06/2019
25/05/2020
25/05/2020
Account: 19-07780
Name: NAMULEME AMIIRAH
Category: Active
Froms: /Date(1560891600000)/
Tos: /Date(1590354000000)/
19/06/2019
19/06/2019
25/05/2020
25/05/2020
Account: 19-07781
Name: NANKABIRWA NAJIWA
Category: Active
Froms: /Date(1560891600000)/
Tos: /Date(1590354000000)/
19/06/2019
19/06/2019
25/05/2020
25/05/2020
Account: 99-00004
Name: NKABIRWA RYAN
Category: Active
Froms: /Date(1560891600000)/
Tos: /Date(1590354000000)/
19/06/2019
19/06/2019
25/05/2020
25/05/2020
result: Active
after sum
[{"Account":"19-07561","Name":"MAKUMBI TARIQ AZIZI","Stream":"R","Category":"Active","Country":"P2","Froms":"\/Date(1560891600000)\/","Tos":"\/Date(1590354000000)\/"},{"Account":"19-07780","Name":"NAMULEME AMIIRAH","Stream":"E","Category":"Active","Country":"P1","Froms":"\/Date(1560891600000)\/","Tos":"\/Date(1590354000000)\/"},{"Account":"19-07781","Name":"NANKABIRWA NAJIWA","Stream":"K","Category":"Active","Country":"PRE","Froms":"\/Date(1560891600000)\/","Tos":"\/Date(1590354000000)\/"},{"Account":"99-00004","Name":"NKABIRWA RYAN","Stream":"X","Category":"Active","Country":"P1","Froms":"\/Date(1560891600000)\/","Tos":"\/Date(1590354000000)\/"}]
07/04/2020
07/04/2020
False
[{"Account":"19-07561","Expressed":"END TERM 1 2019"},{"Account":"19-07561","Expressed":"END TERM 2 2019"},{"Account":"19-07561","Expressed":"END TERM 3 2019"},{"Account":"19-07561","Expressed":"MID TERM 1 2019"},{"Account":"19-07561","Expressed":"MID TERM2 2019"},{"Account":"19-07561","Expressed":"MID TERM3 2019"}]
Account: 19-07561
Expressed: END TERM 1 2019
Account: 19-07561
Expressed: END TERM 2 2019
Account: 19-07561
Expressed: END TERM 3 2019
Account: 19-07561
Expressed: MID TERM 1 2019
Account: 19-07561
Expressed: MID TERM2 2019
Account: 19-07561
Expressed: MID TERM3 2019
[{"Account":"19-07561","balance":0,"class":"P2","Stream":"R","Names":"MAKUMBI TARIQ AZIZI","autofield":1},{"Account":"19-07780","balance":0,"class":"P1","Stream":"E","Names":"NAMULEME AMIIRAH","autofield":1},{"Account":"19-07781","balance":0,"class":"PRE","Stream":"K","Names":"NANKABIRWA NAJIWA","autofield":1},{"Account":"99-00004","balance":0,"class":"P1","Stream":"X","Names":"NKABIRWA RYAN","autofield":1}]
Account: 19-07561
Amount: 0
Class: P2
Stream: R
Names: MAKUMBI TARIQ AZIZI
autofield: 1
Account: 19-07780
Amount: 0
Class: P1
Stream: E
Names: NAMULEME AMIIRAH
autofield: 1
Account: 19-07781
Amount: 0
Class: PRE
Stream: K
Names: NANKABIRWA NAJIWA
autofield: 1
Account: 99-00004
Amount: 0
Class: P1
Stream: X
Names: NKABIRWA RYAN
autofield: 1
[{"anouncement":"Notice:Subscription is 20,000/= per term. This covers all the children you have on the app. it is reciepted from KJS Computer Room where activation is done. By subscribing you will be in position to see your child\u0027s current performance(Marks scores), Past performance and Performance Curves .any app problem  WhatsApp 0782911364","class":"P1","Stream":"S","Type":1},{"anouncement":"Subscription can also be done via mobile money on 0702822227 or 0782911364 reason put the student names and class a receipt will be issued thanks numbers are registered in the names makumbi sulaiman activation is instant","class":"P1","Stream":"P","Type":2},{"anouncement":"We have released a new upgrade of kabojjaapp where homework will be posted. Please uninstall the old version and install the new one released 23/03/2020","class":"P1","Stream":"D","Type":3},{"anouncement":"PLE 2019 Analysis Division  one we got 205 and Division 24 we had 229 students Percentage wise 89.5 Passed in Div 1 and 10.5 Division 2 .We had 19 who scored 4","class":"p1","Stream":"d","Type":4},{"anouncement":"After downloading the Home Work from the KabojjaApp  then open Adobe acrobat reader and click on Files. Under Files .If you have so many PDF files then scroll up to the last file. The Work is Named after a class . E.g PREWORK. P2WORK etc  ","class":"P1","Stream":"D","Type":7}]
Token( at character 0 of [{"anouncement":"Notice:Subscription is 20,000/= per term. This covers all the children you have on the app. it is reciepted from KJS Computer Room where activation is done. By subscribing you will be in position to see your child\u0027s current performance(Marks scores), Past performance and Performance Curves .any app problem  WhatsApp 0782911364","class":"P1","Stream":"S","Type":1},{"anouncement":"Subscription can also be done via mobile money on 0702822227 or 0782911364 reason put the student names and class a receipt will be issued thanks numbers are registered in the names makumbi sulaiman activation is instant","class":"P1","Stream":"P","Type":2},{"anouncement":"We have released a new upgrade of kabojjaapp where homework will be posted. Please uninstall the old version and install the new one released 23/03/2020","class":"P1","Stream":"D","Type":3},{"anouncement":"PLE 2019 Analysis Division  one we got 205 and Division 24 we had 229 students Percentage wise 89.5 Passed in Div 1 and 10.5 Division 2 .We had 19 who scored 4","class":"p1","Stream":"d","Type":4},{"anouncement":"After downloading the Home Work from the KabojjaApp  then open Adobe acrobat reader and click on Files. Under Files .If you have so many PDF files then scroll up to the last file. The Work is Named after a class . E.g PREWORK. P2WORK etc  ","class":"P1","Stream":"D","Type":7}])
Account: null
anouncement: Notice:Subscription is 20,000/= per term. This covers all the children you have on the app. it is reciepted from KJS Computer Room where activation is done. By subscribing you will be in position to see your child's current performance(Marks scores), Past performance and Performance Curves .any app problem  WhatsApp 0782911364
Account: null
anouncement: Subscription can also be done via mobile money on 0702822227 or 0782911364 reason put the student names and class a receipt will be issued thanks numbers are registered in the names makumbi sulaiman activation is instant
Account: null
anouncement: We have released a new upgrade of kabojjaapp where homework will be posted. Please uninstall the old version and install the new one released 23/03/2020
Account: null
anouncement: PLE 2019 Analysis Division  one we got 205 and Division 24 we had 229 students Percentage wise 89.5 Passed in Div 1 and 10.5 Division 2 .We had 19 who scored 4
Account: null
anouncement: After downloading the Home Work from the KabojjaApp  then open Adobe acrobat reader and click on Files. Under Files .If you have so many PDF files then scroll up to the last file. The Work is Named after a class . E.g PREWORK. P2WORK etc
Token( at character 0 of [{"Account":"19-07561","Name":"MAKUMBI TARIQ AZIZI","Stream":"R","Category":"Active","Country":"P2","Froms":"\/Date(1560891600000)\/","Tos":"\/Date(1590354000000)\/"},{"Account":"19-07780","Name":"NAMULEME AMIIRAH","Stream":"E","Category":"Active","Country":"P1","Froms":"\/Date(1560891600000)\/","Tos":"\/Date(1590354000000)\/"},{"Account":"19-07781","Name":"NANKABIRWA NAJIWA","Stream":"K","Category":"Active","Country":"PRE","Froms":"\/Date(1560891600000)\/","Tos":"\/Date(1590354000000)\/"},{"Account":"99-00004","Name":"NKABIRWA RYAN","Stream":"X","Category":"Active","Country":"P1","Froms":"\/Date(1560891600000)\/","Tos":"\/Date(1590354000000)\/"}])
Name: MAKUMBI TARIQ AZIZI
Category: Active
Class: P2
Stream: R
Froms: /Date(1560891600000)/
Tos: /Date(1590354000000)/
19/06/2019
19/06/2019
25/05/2020
25/05/2020
Teacher: NANKUNDA SUSAN
Phone: 0772879545
Phone: 0702879545
0782911364
[{"Teacher":"NANKUNDA SUSAN","Phone":"0772879545","Phone2":"0702879545"}]
Name: NAMULEME AMIIRAH
Category: Active
Class: P1
Stream: E
Froms: /Date(1560891600000)/
Tos: /Date(1590354000000)/
19/06/2019
19/06/2019
25/05/2020
25/05/2020
Teacher: ISABIRYE AGNESS
Phone: 0772645386
Phone: 0701931003
0782911364
[{"Teacher":"ISABIRYE AGNESS","Phone":"0772645386","Phone2":"0701931003"}]
Name: NANKABIRWA NAJIWA
Category: Active
Class: PRE
Stream: K
Froms: /Date(1560891600000)/
Tos: /Date(1590354000000)/
19/06/2019
19/06/2019
25/05/2020
25/05/2020
Teacher: KASIRYE FATUMA
Phone: 0759049975
Phone: 0701809461
0782911364
[{"Teacher":"KASIRYE FATUMA","Phone":"0759049975","Phone2":"0701809461"}]
Name: NKABIRWA RYAN
Category: Active
Class: P1
Stream: X
Froms: /Date(1560891600000)/
Tos: /Date(1590354000000)/
19/06/2019
19/06/2019
25/05/2020
25/05/2020
0782911364
[]
6
** Activity (main) Pause, UserClosed = false **
** Activity (sharetoemailaddress) Create, isFirst = true **
** Activity (sharetoemailaddress) Resume **
Status: READY
Class: P1
Category: NEW HOMEWORK READY
NEW HOMEWORK READY
Error occurred on line: 229 (Sharetoemailaddress)
java.io.FileNotFoundException: /data/user/0/com.kccug.kabojjajuniorapp/files/virtual_assets/storage/emulated/0/download/p1work.pdf (No such file or directory)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:231)
    at java.io.FileInputStream.<init>(FileInputStream.java:165)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:204)
    at anywheresoftware.b4a.objects.streams.File.Copy(File.java:340)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

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

Makumbi

Well-Known Member
Licensed User
FilePath includes the full path so the result path is incorrect. What are you trying to copy from File.DirAssets?

iam getting this downloading this file from the server so that i can send it as an attachment to my mail
B4X:
DownloadAndSaveFileP1("http://kccug.com/KabojjaApp/work/P1WORK.PDF")
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
iam getting this downloading this file from the server so that i can send it as an attachment to my mail
B4X:
DownloadAndSaveFileP1("http://kccug.com/KabojjaApp/work/P1WORK.PDF")

this is the origin where the work comes from
 
Upvote 0
Top