Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic Native HTTP does not work for Anroid 9 (Pie) and up?

I've created an app that connects successfully to our server using Ionic Native HTTP, testing it with Samsung Galaxy J7 Prime OS version Marshmallow and several others that were not yet under Android Pie. For some reason, when I tested it with a device under Android Pie, it won't work anymore and I'm receiving CORS policy issues. Has anybody encountered a similar issue? Is there a workaround for this? Unfortunately, modifications within the server config is not an option. I've also read some solutions about proxy but am not sure how to implement them.

Versions: cordova-plugin-advanced-http: 2.1.1 ionic-native/http: 5.8.0

like image 536
Pete Avatar asked Jun 28 '19 01:06

Pete


People also ask

How do you use ionic native HTTP?

To use HTTP Native plugin in component, first import HTTP class then add in the constructor to use its methods: //home. page. ts import { Component } from '@angular/core'; import { HTTP } from '@ionic-native/http/ngx'; @Component({ selector: 'app-home', templateUrl: 'home.

Is ionic still supported?

The Ionic Framework has been 100% open source (MIT) since the very beginning, and always will be. Developers can ensure Ionic is the right choice for their cross-platform apps through Ionic's community maintenance strategy.

How do I get the Android version on ionic?

ionic. Platform. version(); You can use the above to get the Major version of the Device OS.

Is ionic native app?

Ionic is an open-source UI and Native API framework. It provides cross-platform UI components and native API functionality for building iOS, Android, Electron, and web apps using standard web technologies. The first version of Ionic was released in 2013. The current version, 6.0.


1 Answers

Android P requires HTTPS by default. What this means is that if you are using unencrypted HTTP requests in your app, the app will work fine in all lower versions than Android P.

To avoid this security exception, try below changes in your app code.

In AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >
        ...
    </application>
</manifest>

and in res/xml add file named : network_security_config.xml

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        //  Add host of your download URL in below line. 
        //   ie. if url is  "https://www.google.com/search?source=...."
        //   then just add "www.google.com"
        <domain includeSubdomains="true">www.google.com</domain>
    </domain-config>
</network-security-config>
like image 193
DHAVAL A. Avatar answered Nov 11 '22 22:11

DHAVAL A.