8

i have an cordova pp i am calling a post method in controller it works in browser , but in build and debug apk i get the error

ionic.bundle.js:23826 POST http://somedomain.com/api/account/validation net::ERR_CACHE_MISS

my angular controller

.controller('splashCtrl', function ($scope, $state,$http, userManager, serverConfig) {
    //check if the user exist else it will redirect to login 
    $scope.authenticate = function () {

        $http.post(serverConfig.serverUrl + '/api/account/validation').success(function (res,status) {

            if (status == '200') {

                //check if the user need to change password
                if (window.localStorage.getItem('shouldChangePassword') && window.localStorage.getItem('shouldChangePassword')=='true') {
                    $state.go('setPassword');
                    return;
                }

                $state.go('tab.category');
            }

        }).error(function (data, status) {
            console.log(status)
        })


    }

    $scope.authenticate();


})

any suggestion ?

1
  • have you added the permission in manifest file? Oct 15, 2016 at 20:09

3 Answers 3

9

This Error means you don't have access to internet.There are two ways you can provide this access by changing these files

1.AndroidManifest.xml

add these following permission

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NETWORK_ACCESS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

2. config.xml

For this you are going to need this plugin

cordova plugin add cordova-custom-config

after adding this plugin , add these lines in you config.xml

<platform name="android">
   <config-file target="AndroidManifest.xml" parent="/*">
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permissions.NETWORK_ACCESS" />
      <uses-permission android:name="android.permissions.ACCESS_NETWORK_STATE" />
   </config-file>
</platform>

You can try it . Hope it helps you .Thanks

5
  • i havent test this , but a while ago it was working , i suspect a phonega-push-notofication plugin installation and removal cause this problem . Oct 16, 2016 at 5:22
  • You might need to ensure the android namespace is declared in your config.xml file: xmlns:android="http://schemas.android.com/apk/res/android"
    – David M.
    Jan 29, 2017 at 15:46
  • @user6599525 yes , for some reason this issue also happened to me when after removing the phonegap-push-notification.
    – Rpant
    May 29, 2019 at 19:50
  • The second solution worked once I surrounded the user-permission tags with a CDATA section
    – dankuck
    Sep 17, 2020 at 23:01
  • I can concur with the comment about "phonega-push-notofication plugin installation and removal". I had a project containing 2 apps where app1 used PNs and app2 didnt. So my build script would remove plugin "cordova-plugin-push" for app2 and add it for app1. This seemed to work for a while untl I started getting ERR_CACHE_MISS for app2. Solved by not removing plugin. thanks for the tip
    – Rhubarb65
    Apr 9, 2021 at 9:02
7

If you encounter this problem after removing a plugin or installing a plugin then this solution might work for you.

cordova platform remove android
cordova platform add android

There is no harm in trying it even if you've not installed or removed any plugin.

1
0

Note that if you have recently uninstalled a plugin and it started happening, then the solution by David Addoteye to remove and add the platform back may do it, worked for me.

1

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.