4

I am trying to get a very simple cordova application deployed on android. It is supposed to startup and then pull in a list of countries via angular $http and display them.

For some reason it can't access the internet, to simplify the test, I've added an images tag that displays an image on the net. The image is not displaying either.

I can't get a connection to jsconsole.com working either.

I've tested it on a real device and an emulator. In both cases the app can't access the net but I can browse the net on the device and emulator.

I've included the following in my config.xml

<access origin="*" />

I've also checked the generate AndroidManifest.xml file it contains the following permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

What am I missing?

here is the full config file:

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0"
    id="com.domain.app" version="1.0.0">
    <name>app</name>

    <description>
        A sample Apache Cordova application that responds to the
        deviceready
        event.
    </description>

    <author href="http://www.eclipse.org/thym" email="thym-dev@eclipse.org">
        Eclipse.org -
        Thym
    </author>

    <content src="index.html" />

    <access origin="*" />
    <preference name="fullscreen" value="true" />
    <preference name="webviewbounce" value="true" />
    <preference name="LogLevel" value="VERBOSE" />


    <feature name="App">
        <param name="android-package" value="org.apache.cordova.App" />
    </feature>
    <feature name="Compass">
        <param name="android-package"
            value="org.apache.cordova.deviceorientation.CompassListener" />
    </feature>
    <feature name="Device Orientation">

    <param name="id" value="cordova-plugin-device-orientation" /></feature>
    <feature name="Device">
        <param name="android-package" value="org.apache.cordova.device.Device" />
        <param name="id" value="cordova-plugin-device" />
    </feature>
    <feature name="Notification">
        <param name="android-package" value="org.apache.cordova.dialogs.Notification" />

    <param name="id" value="cordova-plugin-dialogs" /></feature>
    <feature name="NetworkStatus">
        <param name="android-package"
            value="org.apache.cordova.networkinformation.NetworkManager" />
    </feature>
    <feature name="Network Information">
        <param name="id" value="cordova-plugin-network-information" />
    </feature>

    <engine name="android" version="4.1.0"/>
</widget>

Here is the manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.domain.app"
    android:hardwareAccelerated="true"
    android:versionCode="100008"
    android:versionName="1.0.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="22" />

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:hardwareAccelerated="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:supportsRtl="true" >
        <activity
            android:name="com.domain.app.MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
            android:label="@string/activity_name"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.Black.NoTitleBar"
            android:windowSoftInputMode="adjustResize" >
            <intent-filter android:label="@string/launcher_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Rian
  • 1,243
  • 2
  • 17
  • 22

3 Answers3

16

If you are using cordova 5 or above, you should use whitelist plugin

Also you should add this to your config.xml:

<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" />

You can be more concrete if you want.

And also add this meta to your index.html, or main page

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
Víctor
  • 3,029
  • 3
  • 28
  • 43
  • 3
    Thanks, I did not know about the whitelist plugin, I've included those and added the meta tag as you suggested. Unfortunately that has not solved the problem. I am now trying on a new emulator and getting a http status 404 instead of status 0. – Rian Sep 16 '15 at 12:06
  • In the device are you having the same issue? – Víctor Sep 16 '15 at 12:14
  • Yeah, same problem on the device. I actually had to trash the project and start again, but I needed this advice, so I've accepted it as the answer, thanks for your help. – Rian Sep 16 '15 at 15:19
4

There also seems to be a separate issue where freshly created apps, or apps upgraded from older version of Cordova will have cordova-plugin-whitelist@1 installed automatically.

For some reason, this version of plugin does not work when installed in this automatic way (including the version installed by cordova create!) even with proper CSP and access tags.

Removing plugin and replacing it with cordova-plugin-whitelist@latest seems to fix the problem, up to and including to cause subsequent reinstallation of cordova-plugin-whitelist@1 to function properly.

Annar Hiid
  • 51
  • 2
  • Thanks for sharing, I use Visual Studio Tools For Cordova and nothing worked until I uninstalled and installed the plugin. Seems real stupid :) – Ilya Chernomordik Dec 18 '16 at 11:10
0

Remove your entire workspace if you are using android 10>

  • there is no whitelist-plugin
  • there is a lot of issues with access and dependencies

Install Cordova 8.0 and android 6-8