im facing a problem with download manmger
if i downloaded more than one file under one name for ex: "file.mp4"
then next time i download another file with the same name it will be named "file-1.mp4" then "file-2.mp4" and so on..
so i want to know what is my downloaded file name
i found that "DownloadManager1.COLUMN_LOCAL_FILENAME" should get the name
but it is not working im getting this value "local_filename" instead of the read file name
any ideas ?
if i downloaded more than one file under one name for ex: "file.mp4"
then next time i download another file with the same name it will be named "file-1.mp4" then "file-2.mp4" and so on..
so i want to know what is my downloaded file name
i found that "DownloadManager1.COLUMN_LOCAL_FILENAME" should get the name
but it is not working im getting this value "local_filename" instead of the read file name
any ideas ?
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: DownloadManager Demo
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Activity module
Sub Process_Globals
Dim DOWNLOAD_ADDRESS As String="http://www.b4x.com/android/images/wiki_logo.png"
Dim DOWNLOAD_FILENAME As String="wiki_logo.png"
' DownloadId is a unique identifier assigned by the DownloadManager to this download task
Dim DownloadId As Long
End Sub
Sub Globals
Dim DownloadButton As Button
Dim DownloadManager1 As DownloadManager
Dim ImageView1 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
' RegisterReceiver enables DownloadManager to raise events
DownloadManager1.RegisterReceiver("DownloadManager1")
' Utils is a helper code module
If Utils.IsInitialized=False Then
Utils.Initialize(DownloadManager1)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub DownloadButton_Click
Dim DownloadManagerRequest1 As DownloadManagerRequest
DownloadManagerRequest1.Initialize(DOWNLOAD_ADDRESS)
DownloadManagerRequest1.Description="DownloadManager demo"
' save the download to external memory
' note you must manually update your project's manifest file adding android.permission.WRITE_EXTERNAL_STORAGE
DownloadManagerRequest1.DestinationUri="file://"&File.Combine(File.DirRootExternal, DOWNLOAD_FILENAME)
DownloadManagerRequest1.Title=DOWNLOAD_FILENAME
DownloadManagerRequest1.VisibleInDownloadsUi=True
DownloadId=DownloadManager1.Enqueue(DownloadManagerRequest1)
End Sub
Sub DownloadManager1_DownloadComplete(DownloadId1 As Long)
' this does not guarantee that the download has actually successfully downloaded
' it means a DownloadMananger DownloadManagerRequest has completed
' we need to find that status of that request but only if that request matches the request we started
If DownloadId=DownloadId1 Then
' this is the download request we started
' query the DownloadManager for info on this request
Dim DownloadManagerQuery1 As DownloadManagerQuery
DownloadManagerQuery1.Initialize
DownloadManagerQuery1.SetFilterById(DownloadId)
' you must enable the SQL library to work with the Cursor object
Dim StatusCursor As Cursor
' pass our DownloadManagerQuery to the DownloadManager
StatusCursor=DownloadManager1.Query(DownloadManagerQuery1)
If StatusCursor.RowCount>0 Then
StatusCursor.Position=0
Dim StatusInt As Int
StatusInt=StatusCursor.getInt(DownloadManager1.COLUMN_STATUS)
Log("Download Status = "&Utils.GetStatusText(StatusInt))
If StatusInt=DownloadManager1.STATUS_FAILED Or StatusInt=DownloadManager1.STATUS_PAUSED Then
Dim ReasonInt As Int
ReasonInt=StatusCursor.GetInt(DownloadManager1.COLUMN_REASON)
Log("Status Reason = "&Utils.GetReasonText(ReasonInt))
End If
If StatusInt=DownloadManager1.STATUS_SUCCESSFUL Then
Log(DownloadManager1.COLUMN_LOCAL_FILENAME)
ImageView1.Bitmap=LoadBitmap(File.DirRootExternal, DOWNLOAD_FILENAME)
End If
Else
' always check that the Cursor returned from the DownloadManager Query method is not empty
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
' free system resources
StatusCursor.Close
DownloadManager1.UnregisterReceiver
End If
End Sub