Problema with ionic Android app and specific device

I have this android app built from an Ionic4 project. This app uses the normal http client to send requests to a local REST server. I deployed the app to my personal test device (a generic 7" Android 8 tablet) and the app works as expected.

I then installed in a Huawei 12" tablet, Android 8, and the app also works as expected. But then I installed the app in the customer’s device, a 8" Galaxy Tab 2 running Android 9, and the app runs but any request sent to the REST server fails with an “Uknown error” status code 0. If I try to access the REST server from the device’s browser, it works ok. I even downloaded and installed a REST client and it also worked without problems with the REST server… the problem only happens with my app and on this device.

Any ideas of what to check? I discarded permissions problems already ,since my app has all required permissions.

Victor

Well, it turned out that starting with Android 9, the OS will automatically block any request send under http. The workaround (if you don’t want to implement https on your servers) is to allow http requests for an specific domain or for any domain, editing the resources/android/xml/network_security_config.xml file on your Ionic project.

a) To allow http for an specific domain, add an entry like this for each domain:

<domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">YOUR_DOMAIN</domain>
</domain-config>

b) To allow http access for any domain, add this entry:

<base-config cleartextTrafficPermitted="true"/>

Hope this helps to anyone dealing with this problem.

1 Like