Android Question Problems accessing the WEB server

Lakhtin_V

Active Member
Licensed User
Longtime User
I am developing an application that uses access to my WEB server. The code I wrote always worked successfully, I copied all the relevant lines in different applications and always successfully. Now I am working on a new application, but this already tested code gives an error. The list of libraries and strings in the manifest are the same. What could be the reason?
ResponseError. Reason: java.net.UnknownServiceException: CLEARTEXT communication to gip#####.in######.### not permitted by network security policy, Response:

Connect to WEB server:
    Dim WEBserver As ServerSocket

    Log("                        Instal conect WEB server")
    WEBserver.Initialize(0, "")
'    Try
    Starter.pInternet=True
    If WEBserver.GetMyWifiIP="127.0.0.1" Then Starter.pInternet=False
    If WEBserver.GetMyIP="127.0.0.1" Then Starter.pInternet=False        'this is the local host address
'    If Not(Device.Gettate.EqualsIgnoreCase("CONNECTED")) And server.GetMyWifiIP="127.0.0.1" Then pInternet=False
    Log("                        Test my IP  fnd access to Internet " & Starter.pInternet)
'    Catch
'        Log(LastException)
'        Starter.pInternet=False
'    End Try
    If Starter.pInternet=True Then
'        Try
        Dim job As HttpJob
        job.Initialize("internet_connection", Me)
        job.Download("http://gi######.#####.###/g#####.php")
        Wait For(job) JobDone(job As HttpJob)
        Sleep(2000)
        Log("                    Result conect to WEB server" & job.Success )
        If job.Success Then
            Dim Res As String
            Res = job.GetString
            Dim parser As JSONParser
            parser.Initialize(Res)
            Dim data As List
            data = parser.NextArray 'returns a list with map
            Dim m As Map, Answer As String, Quantity As Int
            m = data.Get(0)
            Answer=m.Get("answer")
            Quantity=m.Get("quantity")
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
A quick search using this forums search box with the error message "CLEARTEXT communication" came up with this post:

 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
If the problem is in the security certificate on the WEB server side
not a valid certificate? No Certificate at all?
then why do older versions of the application work fine now?
Because GOOGLE is RESTRICTING the use of http for securityreasons.

Espect more restrictions in every newer Androids.
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
Your advice helped! I added the line to the manifest
SetApplicationAttribute(android:usesCleartextTraffic, "true")
and got the desired result, thank you very much!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
and got the desired result, thank you very much!
Note that you are NOT using Secure connections.
- Setup a SSL-Certificate and use https instead is the correct solution.
- Google may disallow/deprecate android:usesCleartextTraffic in the future.
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
not a valid certificate? No Certificate at all?

Because GOOGLE is RESTRICTING the use of http for securityreasons.

Espect more restrictions in every newer Androids.
BUT the old code works on the same smartphone, on which the new code does not work. I added a line to the manifest and everything became OK.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
BUT the old code works on the same smartphone
Is the old Code USING targetsdk 33+? No, it is not.
Change the code to use a higher targetsdk and they will not run too.

As written: using android:usesCleartextTraffic is NOT the Solution! It is just a workaround which door may be closed in future by Google.
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
You are absolutely right in my new version the target SDK version is 34 and in the old ones 31-32, I ask you to give me advice if in my application the target SDK version in the manifest is less than the real one on the smartphone, then my application will not work.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…