1

So i'm building an Ionic App with API calls, everything works fine when i run it on the browser and i get all my data.

But when i build the app (ionic cordova build android) and install the .apk in my phone, i get NO data, the view is just empty and i don't know why.

I followed instructions that i found here but still nothing.

I even installed "android-permissions" cordova plugin as explained in this question but when i'm installling the app one my phone, it says that the app does not require any permission.

I'm lost and don't really know why it is not working. Help neede please !.

Information about the project

Created using "ionic start appName blank --type=angular"

Ionic Framework :

@ionic/angular 4.9.1

Ionic CLI :

5.4.1

Cordova CLI :

9.0.0

Cordova Platforms : 

android 8.1.0

Thank you

9
  • what are you using as your back-end? Commented Sep 25, 2019 at 13:16
  • I'm using PHP and MySql. The whole backend (php scripts + mysql database) is hosted on a web server Commented Sep 25, 2019 at 13:17
  • Have you tried to Debug your application via Chrome?? Commented Sep 25, 2019 at 13:19
  • Use Chrome Debug tool to Check debug your app: To use Chrome Debug type chrome://inspect/#devices in your chrome Search bar. Connect your Mobile(enable Developer option & USB debugging from settings) via Cable you will see your device slick on it a New debugger window will open. check console for errors / warnings. Commented Sep 25, 2019 at 13:19
  • No i haven't, but it is actually working on Chrome when i run the ionic serve command, everything works fine Commented Sep 25, 2019 at 13:20

1 Answer 1

1

This could be a whitelisting or, if you have Android 9 and your API does not use TLS, a network security issue.

Whitelisting

Add the tag <access origin="https://your-server.com" /> to your config.xml.

Network Security

To allow Android 9 devices to access http:// (non-TLS) APIs, additional configuration is required. In a Cordova app, perform the following steps:

  1. Create a file called network_security_config.xml in your project root containing the following:
    <?xml version="1.0" encoding="utf-8"?>
      <network-security-config>
        <domain-config cleartextTrafficPermitted="false">
      </domain-config>
    </network-security-config>
  1. Add this to your config.xml to include the new configuration in your Android Manifest:
    <platform name="android">
        ...
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:networkSecurityConfig="@xml/network_security_config" />
        </edit-config>
        <resource-file src="network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
        ...
    </platform>

Rebuild the Android platform (i.e. ionic cordova platform rm android and ionic cordova platform add android etc.) and it should work from your device.

Sign up to request clarification or add additional context in comments.

16 Comments

Alright thank you, i'm going to try it right now and come back
Does your endpoint use SSL? And does your request complete with a 200 response but there is not payload, or does the request error out?
No it does not use SSL. And the request responses with a 200 code. Everything works fine on the browser/computer. The problem is the Android device that i install the app on, i'm seeing no data. And i don't know if it is a CORS issue or something with the Android permissions (internet, network_state...)
Are you on Android 9? They require you to use SSL. Have a look at this question: stackoverflow.com/questions/51902629/…
Hey @kavindhi , i'll be glad to help. I'm a little bit limited in the comments so i made a file that explains the issue and how to solve it. Here is the link. I stay tuned for more questions
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.