1

My android app is developed with hybrid technology method (html 5 , css , javascript) at first I build it with phonegap cli 8 and everything was right and working fine. but when google is no longer allow cli 8 I recently rebuild my app with cli 9 and sdk version 28 but I face problems where I don't know what exactly happens. All my ajax calls are not working to http servers but I can call ajax calls to https server e.g I can call ajax request to youtube apis.

here is my config.xaml file content

    <?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.myDomain" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
   <name>AppName</name>
    <description>
        Application
    </description>
    <author email="info@myDomain.com" href="http://example.com ">
       author info
    </author>
    <content src="index.html" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="28" />
    <preference name="phonegap-version" value="cli-9.0.0" />
    <plugin name="cordova-plugin-battery-status" source="npm" spec="~1.1.1" />
    <plugin name="cordova-plugin-camera" source="npm" spec="~2.1.1" />
    <plugin name="cordova-plugin-media-capture" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-console" source="npm" spec="~1.0.2" />
    <plugin name="cordova-plugin-contacts" source="npm" spec="~2.0.1" />
    <plugin name="cordova-plugin-device" source="npm" spec="~1.1.1" />
    <plugin name="cordova-plugin-device-motion" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-device-orientation" source="npm" spec="~1.0.2" />
    <plugin name="cordova-plugin-dialogs" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-file" source="npm" spec="~4.1.1" />
    <plugin name="cordova-plugin-file-transfer" source="npm" spec="~1.5.0" />
    <plugin name="cordova-plugin-geolocation" source="npm" spec="~2.1.0" />
    <plugin name="cordova-plugin-globalization" source="npm" spec="~1.0.3" />
    <plugin name="cordova-plugin-inappbrowser" source="npm" spec="~1.3.0" />
    <plugin name="cordova-plugin-media" source="npm" spec="~2.2.0" />
    <plugin name="cordova-plugin-network-information" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-splashscreen" source="npm" spec="~3.2.1" />
    <plugin name="cordova-plugin-statusbar" source="npm" spec="~2.1.2" />
    <plugin name="cordova-plugin-vibration" source="npm" spec="~2.1.0" />
    <plugin name="cordova-plugin-whitelist" source="npm" spec="~1.3.4" />
    <platform name="android">
       <preference name="SplashScreenDelay" value="8000" />
        <icon density="ldpi" src="www/res/icon/android/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="www/res/icon/android/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="www/res/icon/android/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="www/res/icon/android/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="www/res/icon/android/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="www/res/icon/android/drawable-xxxhdpi-icon.png" />
        <splash density="land-ldpi" src="www/res/screen/android/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="www/res/screen/android/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="www/res/screen/android/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="www/res/screen/android/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="www/res/screen/android/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="www/res/screen/android/drawable-land-xxxhdpi-screen.png" />
        <splash density="port-ldpi" src="www/res/screen/android/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="www/res/screen/android/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="www/res/screen/android/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="www/res/screen/android/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="www/res/screen/android/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="www/res/screen/android/drawable-port-xxxhdpi-screen.png" />
    </platform>
    <splash src="splash.png" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
    <allow-intent href="market:*" />
    </platform>

    </widget>

and this is my meta tag for origin(content security) access purpose

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval';connect-src 'self' http://www.example.com:80" />

when I call an ajax call to youtube (https) as fallowing code:

  $.ajax({
                cache: false,
                url: 'https://www.googleapis.com/youtube/v3/playlists',
                type: "GET",
                contentType: "application/JSONP; charset=utf-8",
                dataType: "JSONP",
                crossDomain: true,
                data: {'part': 'snippet,contentDetails','channelId': 'youtubeChannelID', 'key': 'myAppKey'},
                beforeSend: function () {
                    displayloadOn();
                }, success: function (datas) {
                    displayloadOff();
                   console.log(datas);
                }
            })

        }
    });

it works fine and get respected data from youtube.

but when I call ajax to my (http) website as following

$.ajax({
        url: 'http://www.example.com /JSONAPI.php',  //suppose example.com is my domain 
        method: 'get',
        dataType:"JSON",
        data: {'f': APIRouteName,'NumberOfRecords': NumberOfRecords, 'NumberOfOffset': NumberOfOffset},
        beforeSend: function () {
            displayloadOn();
            checkAjaxStatus=false;
        }, success: function (datas) {

         console.log(datas);
        }
    })

it always fails in cordova cli 9 and sdk version 28 and its fine with cli 8.

please I don't know what is wrong? it works fine in local environment but after building it with phonegap build and run it into my sumsung s8+ phone all ajax calls to my website is not working but only I can call to youtube api.

johni
  • 23
  • 4
  • 1
    Did you try [enabling `clearText` traffic](https://stackoverflow.com/questions/54752716/why-am-i-seeing-neterr-cleartext-not-permitted-errors-after-upgrading-to-cordo), since your back server uses unsecure http. – Maheswaran Ravisankar Nov 02 '19 at 11:52
  • exactly it was what i was looking for thank you – johni Nov 04 '19 at 08:06

1 Answers1

1

You should use https connection to call ajax I was also facing the same issue but after some research, I found that, According to API level 28, apps should use https connection

So in ajax call, you should use https