Android Question Check if a file has already downloaded

Discussion in 'Android Questions' started by kozbot, Aug 17, 2015.

  1. kozbot

    kozbot Member Licensed User

    Hi all,

    I just wanna check if there is a way that I can use Download manager to check first if a file has been downloaded, and if it is, then open the already downloaded one, but if not, then go ahead and download the file. Here's my code:

    Sub Button2_Click
    Dim DownloadManagerRequest1 As DownloadManagerRequest
    "D16 Installer"
    "file://"&File.Combine(File.DirRootExternal, DOWNLOAD_FILENAME)
    End Sub

    Sub DownloadManager1_DownloadComplete(DownloadId1 As Long)
    If DownloadId=DownloadId1 Then
    Dim DownloadManagerQuery1 As DownloadManagerQuery
    Dim StatusCursor As Cursor
    If StatusCursor.RowCount>0 Then
    Dim StatusInt As Int
    Log("Download Status = "&Utils.GetStatusText(StatusInt))

    If StatusInt=DownloadManager1.STATUS_FAILED Or StatusInt=DownloadManager1.STATUS_PAUSED Then
    Dim ReasonInt As Int
    Log("Status Reason = "&Utils.GetReasonText(ReasonInt))
    End If
    If StatusInt=DownloadManager1.STATUS_SUCCESSFUL Then
    Dim intent1 As Intent
    "file://"&File.Combine(File.DirRootExternal, DOWNLOAD_FILENAME))
    "Choose PDF Viewer")
    End If
    Log("The DownloadManager has no trace of our request, it could have been cancelled by the user using the Android Downloads app or an unknown error has occurred.")
    End If
    End If
    End Sub
    Thanks in advance!
  2. DonManfred

    DonManfred Expert Licensed User

    if file.exists(....) then
    do the work for a file already downloaded...
    do the download
    end if
    PoleStar likes this.
  3. kozbot

    kozbot Member Licensed User

    Thanks heaps... I don't know why I didn't think of if file.exists...

    Thanks for the help!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice