Ionic3 + HTTP call + Android 9.0.4

Not only this did not work, but it made my app break in many devices.

If anyone is going to try this, be careful.
My app had never had more than 1 error or ANR on Google Play.
When I deployed the version with this fix, the errors raised to 62, affecting 11 users.

in config.xml, the root of the ionic project

I had same issue on Android 9 Devices. First I have tried with updating config.xml by adding the following:

<platform name="android">

        <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:usesCleartextTraffic="true" />
        </edit-config>
    </platform>

Still faced sames issue. My Webserver is enabled CORS. But Same issue.
After surfing on internet for a solution:

Updated the network_security_config.xml (resources/android/xml
) file with the following code

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
   <base-config cleartextTrafficPermitted="true">
       <trust-anchors>
           <certificates src="system" />
       </trust-anchors>
   </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain>api.mydomain.in</domain>
    </domain-config>
</network-security-config>

and now issue is solved
 Please let me know if anyone facing the issues. Thank You

5 Likes

I have this issue please help me to solve this. Link

Domain name Add SSL certificate working!!!

1 Like

hello,

<uses-sdk android:targetSdkVersion="27" />

use this SDK version in your AndroidManifest.xml file and it will work in android 9.

thanks.

Merci @suhailparad pour ta rĂ©ponse, j’ai bien reçu Ă  faire fonctionner sous ionic 5.2 et android 9
Post 23 super

Good afternoon.
If the same problem occurs, please correct this error by installing an ssl certificate in my domain. You can get a free ssl certificate for your domain, let’s encrypt.
It worked for me.

1 Like

Thanks alot this solved my problem

This worked for me. Thanks a lot :grinning:

When run android 8 API 27, it is working(subscribe out put success). But when run android 9 API 28, it is NOT working.(subscribe out put error) What is the reason for this? Please help me.

import { HttpClient, HttpHeaders, HttpErrorResponse } from ‘@angular/common/http’;
import { Component } from ‘@angular/core’;

@Component({
selector: ‘app-home’,
templateUrl: ‘home.page.html’,
styleUrls: [‘home.page.scss’],
})

export class HomePage {

constructor(public httpClient: HttpClient) { }

sendPostRequest () {

var headers = new HttpHeaders();
headers.append("Accept", 'text/plain');
headers.append('Content-Type', 'text/plain; charset=utf-8');

const requestOptions = { headers: headers };

this.httpClient.get("http://192.168.8.101/gm_inv_svr/connection_checker.php", requestOptions)

  .subscribe(result  => {
    alert("okkkkkkkk " + result );
  }, error => {
    console.log(error);
    alert("Error 6 " + error.error + " \n" + error.message + " \n" + error.names);
  });

}

}

connection_checker.php

<?php header("Access-Control-Allow-Origin: *"); echo '{ "con_ststus": true, "msg":"network connection sucessful." }'; ?>

merci cher ami ! j’avais ce problĂšme depuis 2 semaines et sans rĂ©ponse mais la ça marche mieux avec android 9 . sois mĂȘme bĂ©nis :crossed_fingers: