B4A Library Downloading with resume

hi this library helps you download a file with resume support
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
Dim dm As Downloading

End Sub
Sub Service_Create
dm.initialize("test")
End Sub

Sub Service_Start (StartingIntent As Intent)

dm.Download("http://xxxxx",File.DirRootExternal&"/test.zip",0)

End Sub

Sub Stop
dm.stop
End Sub

Sub test_DownloadStatus (Status As Long , Total As Long)

End Sub

Sub test_DownloadFinish (Success As Boolean)

End Sub

the third number in the method Download is start download from byte the file
NOTE:
this lib writes to append files so if you want to restart a download you must delete the old file before start downlod
this library supports only 1 download
add this line to your manifest:
B4X:
AddApplicationText(<service android:name="anywheresoftware.b4a.downloadmanager.DownloadService"/>)
 

Attachments

  • Downloading.zip
    5 KB · Views: 308
Last edited:

mohsen nasrabady

Active Member
Licensed User
Longtime User
Version 1.01
this version is based on apache and works better and some fixes
 

Attachments

  • Downloading.zip
    5.8 KB · Views: 282

Devv

Active Member
Licensed User
Longtime User
app is crashing

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    dm.initialize("test")
    dm.Download("http://download.thinkbroadband.com/5MB.zip",File.DirRootExternal& "/testR.apk",0)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Stop
dm.Stop
End Sub

Sub test_DownloadStatus (Status As Long , Total As Long)
    ToastMessageShow("status: " & Status & " Total: " & Total,False)
End Sub

Sub test_DownloadFinish (Success As Boolean)
ToastMessageShow("done",False)
End Sub
android 4.3, Galaxy S3
 

aidymp

Well-Known Member
Licensed User
Longtime User
app is crashing

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    dm.initialize("test")
    dm.Download("http://download.thinkbroadband.com/5MB.zip",File.DirRootExternal& "/testR.apk",0)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Stop
dm.Stop
End Sub

Sub test_DownloadStatus (Status As Long , Total As Long)
    ToastMessageShow("status: " & Status & " Total: " & Total,False)
End Sub

Sub test_DownloadFinish (Success As Boolean)
ToastMessageShow("done",False)
End Sub
android 4.3, Galaxy S3

HI, Devv did you get this working? if so any tips please?

Thanks

Aidy
 

aidymp

Well-Known Member
Licensed User
Longtime User
search in the forum
u must add a service module to ur project

YES! i understand that I have the code in a service module, but HOW do i start a download?

Downloader Module

B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region



Sub Service_Destroy

End Sub
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
Dim dm As Downloading

End Sub
Sub Service_Create
dm.initialize("test")
End Sub

Sub Service_Start (StartingIntent As Intent)

dm.Download("http://ipv4.download.thinkbroadband.com/200MB.zip",File.DirRootExternal&"/test.zip",0)

End Sub

Sub Stop
dm.Stop
End Sub
Sub test_DownloadStatus (Status As Long , Total As Long)
    ToastMessageShow("status: " & Status & " Total: " & Total,False)
End Sub

Sub test_DownloadFinish (Success As Boolean)
ToastMessageShow("done",False)
End Sub


Main Module
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
StartService(Downloader)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

my log shows

B4X:
PackageAdded: package:b4a.example


** Activity (main) Create, isFirst = true **


** Activity (main) Resume **
** Service (downloader) Create **


** Service (downloader) Start **

But nothing happens?

Any tips?
 

aidymp

Well-Known Member
Licensed User
Longtime User
search in the forum
u must add a service module to ur project

Hi Mohsen! Thanks for your help however I am unable to grasp the idea of using this library! and am desperate to implement a download and resume feature in my App!

If you could create a small sample project in B4A, that downloads this file http://download.thinkbroadband.com/200MB.zip and shows how to detect failure, and then resume if necessary! I will send you $30 USD (Sorry if that offends you, but i am out of work) by paypal immediately. I have been trying all day. but cannot get it to even start a download!

Thanks

Aidy
 

mohsen nasrabady

Active Member
Licensed User
Longtime User
i think u forgot add this in your monifest
AddApplicationText(<service android:name="anywheresoftware.b4a.downloadmanager.DownloadService"/>)
 

ibra939

Active Member
Licensed User
Longtime User
thanks i would to know if i can make it for mp3 downloading ?
 

asmag

Member
Licensed User
Longtime User
Hi!

After downloading the file, how i do to download it again another time?
 

asmag

Member
Licensed User
Longtime User
Hi!

Sorry! I mean just to schedule my job to download a same file at any time .. over and over again.. My idea is for using on database aplication that download a file from dropbox cloud after it have uploaded.

Att. asmag
 

Cableguy

Expert
Licensed User
Longtime User
[Quote "aidymp, post: 333603, member: 70838"]No, I added that too![/QUOTE]

I understand your strive... But do remember to breath!!!
Start a blank project a try to get a sample to work... Take a break... Sometimes solutions appear from out of the blue...
 

aidymp

Well-Known Member
Licensed User
Longtime User
[Quote "aidymp, post: 333603, member: 70838"]No, I added that too!

I understand your strive... But do remember to breath!!!
Start a blank project a try to get a sample to work... Take a break... Sometimes solutions appear from out of the blue...[/QUOTE]

I would still pay for a working demo project of this! ;)
 
Top