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