-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNetworkClass.b4a
94 lines (80 loc) · 2.57 KB
/
NetworkClass.b4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Version=7.3
NumberOfModules=1
Module1=Starter
Build1=Default,b4a.example.ckass
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~AddPermission(android.permission.INTERNET)~\n~'End of default text.~\n~
IconFile=
NumberOfFiles=1
File1=1.bal
NumberOfLibraries=3
Library1=core
Library2=networkclass
Library3=httputils2
@EndOfDesignText@
#Region Project Attributes
#ApplicationLabel: NetworkClass
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
#Region Info
'Jamie John
#End Region
Sub Process_Globals
End Sub
Sub Globals
Dim net As networkclass
Private Button1 As Button 'ignore
Private Button2 As Button
Private Label1 As Label
Private Button3 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
net.Initialize("network")
End Sub
Sub Activity_Resume
net.register
End Sub
Sub Activity_Pause (UserClosed As Boolean)
net.remove
End Sub
Sub network_state(a As String)
ToastMessageShow(a, True)
End Sub
Sub Button1_LongClick
End Sub
Sub Button1_Click
'this is a test download sample
net.downloadtest
End Sub
Sub Button2_Click
' register listener and start sampling a large image
net.register
net.startSampling
Dim job As HttpJob
job.Initialize("j", Me)
job.Download("https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73751/world.topo.bathy.200407.3x5400x2700.jpg")
job.Release
End Sub
Sub JobDone (job As HttpJob)
If job.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirDefaultExternal, "test.jpg", False)
File.Copy2(job.GetInputStream, out)
out.Close '<------ very important
Log("FILE DOWNLOADED ! ")
'stop sampling and after few secs an event is raised in this case a toastmessage
net.stopSampling
Else
Log("Error: " & job.ErrorMessage)
End If
End Sub
'Manaul way to get last reading that was sampled
Sub Button3_Click
net.BandwidthQuality
End Sub