Android Question Why is my URL truncated

johnmie

Active Member
Licensed User
Longtime User
As a full-time hobby programmer I like challenges and I love B4X because there is never a dull moment and it is always full of surprises.
E.g. Using Erel's DownloadAndSave routine (which I have before successfully used for years) now throws this error:

ResponseError. Reason: java.net.ConnectException: Failed to connect to www.bizgraphic.ch/192.168.0.118:443, Response:
Maybe 192.168 has something to do with my Wlan settings, the firewall or the VPN I am using or even with Windows 11?

Why and what can be done do correct it?

here is the code
download and save a file:
            Dim URL As String = "https://www.bizgraphic.ch/elxf/elxf-specification.pdf" 'V/downloads/help33_en.vlst"$
            Dim A As String = URL.SubString(URL.lastindexof("/")+1)
            Wait for (Starter.DownloadAndSave(URL, Starter.downloadPath, A)) Complete (Success As Boolean)
            If Success Then
                Log("Download completed")
            Else
                Log("file not found")
            End If
           
    Public Sub DownloadAndSave (Url As String, Dir As String, FileName As String) As ResumableSub
    Log("Download URL="&Url&",   Dir="&Dir&",   File="&FileName)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Url)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim out As OutputStream = File.OpenOutput(Dir, FileName, False) 'TargetFolder, Filename, Append true/false
        File.Copy2(j.GetInputStream, out)
        out.Close
    End If
    j.Release
    Return j.Success
End Sub

Manifest editor:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddPermission(android.permission.MANAGE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
SetApplicationAttribute(android:requestLegacyExternalStorage, true)

Can anybody help this poor guy?
Thank you in advance,
john m.
 

drgottjr

Expert
Licensed User
Longtime User
your code, as posted, works fine here. not sure what the problem is.
log output:
** Activity (main) Create (first time) **
** Activity (main) Resume **
Download URL=https://www.bizgraphic.ch/elxf/elxf-specification.pdf, Dir=/data/user/0/b4a.progress/files, File=elxf-specification.pdf
*** Receiver (httputils2service) Receive (first time) ***
Download completed
4173127 bytes
 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
Thanks for trying. This proves that Erel's code works well and that the error must have to do with Android's constantly changing behavior and security settings.

I forgot that I was looking at the error message on my PC, but in reality it came from my Android Tablet.
I once saw a post by Aeric that pointed in that direction, but can't remember where.
 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
Resolved.
Connection is obviously not automatic. When I first open the browser (Firefox in my case) and later start my app, it works.
Sorry to have you bothered with my stupid and/or ignorant lamentations.
john m.
 
Upvote 0
Top