Cordova 5.0.0 android应用程序无法连接到互联网使用android 4.0.0 [英] Cordova 5.0.0 android app can not connect to internet using android 4.0.0

查看:175
本文介绍了Cordova 5.0.0 android应用程序无法连接到互联网使用android 4.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Windows 7开发cordova应用程序。模拟器可以连接互联网与浏览器,但应用程序失败并出现网络错误



请检查[link here] p>

使用最新的cordova Android 4.0.0 for devleopment



Cordova 5.0.0
Cordova-android 4.0.0



我已经将白名单添加为cordova项目的新插件。请检查此处链接



我的config.xml文件定义如下,访问被给予所有URL。我真的不知道它可能会错了。请指导。

 <?xml version =1.0encoding =UTF-8?& 

< widget xmlns =http://www.w3.org/ns/widgets
xmlns:gap =http://phonegap.com/ns/1.0
id =com.vs.VSMF
version =1.0.0>

< name> VSMF< / name>

< description>
VSMF项目模板。
< / description>

< author href =email =dong_dh@hotmail.com>
Hua Dong
< / author>

<! -
此处启用单独的API权限。
deviceready事件需要device权限。
- >
< feature name =http://api.phonegap.com/1.0/device/>

<! -
如果您不想将任何权限添加到您的应用程序,请将
以下标记添加到您的config.xml;你仍然会有你的应用程序的INTERNET
权限,PhoneGap要求。
- >
< preference name =permissionsvalue =none/>

<! - 使用preference元素自定义您的应用和平台。 - >
<! - < preference name =phonegap-versionvalue =3.4.0/> - > <! - all:当前版本的PhoneGap - >
< preference name =orientationvalue =default/> <! - all:default表示横向和纵向均已启用 - >
< preference name =target-devicevalue =universal/> <! - all:可能值手机,平板电脑或通用 - >
< preference name =fullscreenvalue =true/> <! - all:隐藏屏幕顶部的状态栏 - >
< preference name =disallowOverscrollvalue =true/>
< preference name =webviewbouncevalue =false/> <! - ios:控制当滚动超出顶部时屏幕是否弹起 - >
< preference name =prerendered-iconvalue =true/> <! - ios:if icon is prerendered,iOS will not apply it's gloss to the app's icon on the user's home screen - >
< preference name =stay-in-webviewvalue =false/> <! - ios:外部链接应该在默认浏览器中打开,'true'将使用应用程序生活的webview - >
< preference name =ios-statusbarstylevalue =black-opaque/> <! - ios:black-translucent将显示为黑色,因为PhoneGap网页视图不在状态栏下 - >
< preference name =detect-data-typesvalue =true/> <! - ios:控制数据类型(例如电话号码和日期)是否被系统自动变成链接 - >
< preference name =exit-on-suspendvalue =false/> <! - ios:如果设置为true,应用程序将在按下主页按钮时终止 - >
< preference name =show-splash-screen-spinnervalue =true/> <! - ios:如果设置为false,则微博不会在应用加载时显示在启动屏幕上 - >
< preference name =auto-hide-splash-screenvalue =false/> <! - ios:if设置为false,启动屏幕必须使用JavaScript API隐藏 - >
< preference name =AutoHideSplashScreenvalue =false/>
< preference name =SplashScreenDelayvalue =60000/>
< preference name =disable-cursorvalue =false/> <! - 黑莓:防止鼠标图标/光标在应用上显示 - >
< preference name =android-minSdkVersionvalue =17/> <! - android:目标设备上支持的MIN SDK版本。 MAX版本默认为空。 - >
< preferences name =android-installLocationvalue =auto/> <! - android:应用程式安装位置。 'auto'将选择。 'internalOnly'是设备内存。 'preferExternal'是SDCard。 - >
< preference name =iosExtraFilesystemsvalue =library,library-nosync,documents,document-nosync,cache,bundle,root/>
< preference name =iosPersistentFileLocationvalue =Library/>
< preference name =AndroidExtraFilesystemsvalue =files,external,documents,sdcard,cache,cache-external,root/>
< preference name =AndroidPersistentFileLocationvalue =Internal/>
<! - 也可以在这里添加插件。 - >
<! -
< gap:plugin name =Example/>
可用的插件列表可在https://build.phonegap.com/docs/plugins
- >
< gap:plugin name =org.apache.cordova.console/>
< gap:plugin name =org.apache.cordova.network-information/>

<! - 为每个平台定义应用程序图标。 - >
< icon src =icon.png/>
< icon src =res / icon / android / icon-36-ldpi.pnggap:platform =androidgap:density =ldpi/>
< icon src =res / icon / android / icon-48-mdpi.pnggap:platform =androidgap:density =mdpi/>
< icon src =res / icon / android / icon-72-hdpi.pnggap:platform =androidgap:density =hdpi/>
< icon src =res / icon / android / icon-96-xhdpi.pnggap:platform =androidgap:density =xhdpi/&
< icon src =res / icon / blackberry / icon-80.pnggap:platform =blackberry/>
< icon src =res / icon / blackberry / icon-80.pnggap:platform =blackberrygap:state =hover/&
< icon src =res / icon / ios / icon-57.pnggap:platform =ioswidth =57height =57/>
< icon src =res / icon / ios / icon-72.pnggap:platform =ioswidth =72height =72/>
< icon src =res / icon / ios / icon-57-2x.pnggap:platform =ioswidth =114height =114/&
< icon src =res / icon / ios / icon-72-2x.pnggap:platform =ioswidth =144height =144/&
< icon src =res / icon / webos / icon-64.pnggap:platform =webos/>
< icon src =res / icon / windows-phone / icon-48.pnggap:platform =winphone/>
< icon src =res / icon / windows-phone / icon-173.pnggap:platform =winphonegap:role =background/&

<! - 为每个平台定义应用程序启动屏幕。 - >
< gap:splash src =res / screen / android / screen-ldpi-portrait.pnggap:platform =androidgap:density =ldpi/&
< gap:splash src =res / screen / android / screen-mdpi-portrait.pnggap:platform =androidgap:density =mdpi/&
< gap:splash src =res / screen / android / screen-hdpi-portrait.pnggap:platform =androidgap:density =hdpi/&
< gap:splash src =res / screen / android / screen-xhdpi-portrait.pnggap:platform =androidgap:density =xhdpi/&
< gap:splash src =res / screen / blackberry / screen-225.pnggap:platform =blackberry/>
< gap:splash src =res / screen / ios / screen-iphone-portrait.pnggap:platform =ioswidth =320height =480/&
<差距:泼SRC =RES /屏幕/ IOS /屏幕iphone画像-2x.png差距:平台=IOSWIDTH =640HEIGHT =960/>
<差距:泼SRC =RES /屏幕/ IOS /屏幕的iPad-portrait.png差距:平台=IOSWIDTH =768HEIGHT =1024/>
<差距:泼SRC =RES /屏幕/ IOS /屏幕的iPad-landscape.png差距:平台=IOSWIDTH =1024HEIGHT =768/>
< gap:splash src =res / screen / windows-phone / screen-portrait.jpggap:platform =winphone/>

<! -
定义对外部域的访问。

< access /> - 空白访问标签拒绝访问所有外部资源。
< access origin =*/> - 通配符访问标记允许访问所有外部资源。

否则,您可以指定特定的域:
- >
< access origin =*/> <! - allow local pages - >
< allow-navigation href =*/>
< allow-intent href =*/>
<! -
< access origin =http://phonegap.com/> - 允许任何安全请求http://phonegap.com/
< access origin =http://phonegap.comsubdomains =true/> - 与上述相同,但包含子网域,例如http://build.phonegap.com/
< access origin =http://phonegap.combrowserOnly =true/> - 只允许儿童浏览器打开http://phonegap.com。
- >

< / widget>在androidmenifest.xml文件中的

,还授予

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


解决方案

- 策略元标记?如果您设置Content-Security-Policy元不正确,可能会导致此问题。


I m developing the cordova applicatin using windows 7. The emulator can connect internet with browser but the app failed with network error

check the [link here]

Using the the latest cordova android 4.0.0 for devleopment

Cordova 5.0.0 Cordova-android 4.0.0

I have already added the whitelist as a new plugin to the cordova project. check the link here

My config.xml file is defined as below, the access is given to all URL. I really dont know where it could go wrong. Please advice.

   <?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.vs.VSMF"
        version   = "1.0.0">

    <name>VSMF</name>

    <description>
        VSMF project template.
    </description>

    <author href="" email="dong_dh@hotmail.com">
        Hua Dong
    </author>

    <!--
        Enable individual API permissions here.
        The "device" permission is required for the 'deviceready' event.
    -->
    <feature name="http://api.phonegap.com/1.0/device" />

    <!--
        If you do not want any permissions to be added to your app, add the
        following tag to your config.xml; you will still have the INTERNET
        permission on your app, which PhoneGap requires.
    -->
    <preference name="permissions"                value="none"/>

    <!-- Customize your app and platform with the preference element. -->
    <!-- <preference name="phonegap-version"      value="3.4.0" /> -->      <!-- all: current version of PhoneGap -->
    <preference name="orientation"                value="default" />        <!-- all: default means both landscape and portrait are enabled -->
    <preference name="target-device"              value="universal" />      <!-- all: possible values handset, tablet, or universal -->
    <preference name="fullscreen"                 value="true" />           <!-- all: hides the status bar at the top of the screen -->
    <preference name="disallowOverscroll"         value="true" />
    <preference name="webviewbounce"              value="false" />           <!-- ios: control whether the screen 'bounces' when scrolled beyond the top -->
    <preference name="prerendered-icon"           value="true" />           <!-- ios: if icon is prerendered, iOS will not apply it's gloss to the app's icon on the user's home screen -->
    <preference name="stay-in-webview"            value="false" />          <!-- ios: external links should open in the default browser, 'true' would use the webview the app lives in -->
    <preference name="ios-statusbarstyle"         value="black-opaque" />   <!-- ios: black-translucent will appear black because the PhoneGap webview doesn't go beneath the status bar -->
    <preference name="detect-data-types"          value="true" />           <!-- ios: controls whether data types (such as phone no. and dates) are automatically turned into links by the system -->
    <preference name="exit-on-suspend"            value="false" />          <!-- ios: if set to true, app will terminate when home button is pressed -->
    <preference name="show-splash-screen-spinner" value="true" />           <!-- ios: if set to false, the spinner won't appear on the splash screen during app loading -->
    <preference name="auto-hide-splash-screen"    value="false" />           <!-- ios: if set to false, the splash screen must be hidden using a JavaScript API -->
    <preference name="AutoHideSplashScreen" value="false" />
    <preference name="SplashScreenDelay"          value="60000" />
    <preference name="disable-cursor"             value="false" />          <!-- blackberry: prevents a mouse-icon/cursor from being displayed on the app -->
    <preference name="android-minSdkVersion"      value="17" />              <!-- android: MIN SDK version supported on the target device. MAX version is blank by default. -->
    <preference name="android-installLocation"    value="auto" />           <!-- android: app install location. 'auto' will choose. 'internalOnly' is device memory. 'preferExternal' is SDCard. -->
    <preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
    <preference name="iosPersistentFileLocation" value="Library" />
    <preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />
    <preference name="AndroidPersistentFileLocation" value="Internal" />
    <!-- Plugins can also be added here. -->
    <!--
        <gap:plugin name="Example" />
        A list of available plugins are available at https://build.phonegap.com/docs/plugins
    -->
    <gap:plugin name="org.apache.cordova.console" />
    <gap:plugin name="org.apache.cordova.network-information" />

    <!-- Define app icon for each platform. -->
    <icon src="icon.png" />
    <icon src="res/icon/android/icon-36-ldpi.png"   gap:platform="android"    gap:density="ldpi" />
    <icon src="res/icon/android/icon-48-mdpi.png"   gap:platform="android"    gap:density="mdpi" />
    <icon src="res/icon/android/icon-72-hdpi.png"   gap:platform="android"    gap:density="hdpi" />
    <icon src="res/icon/android/icon-96-xhdpi.png"  gap:platform="android"    gap:density="xhdpi" />
    <icon src="res/icon/blackberry/icon-80.png"     gap:platform="blackberry" />
    <icon src="res/icon/blackberry/icon-80.png"     gap:platform="blackberry" gap:state="hover"/>
    <icon src="res/icon/ios/icon-57.png"            gap:platform="ios"        width="57" height="57" />
    <icon src="res/icon/ios/icon-72.png"            gap:platform="ios"        width="72" height="72" />
    <icon src="res/icon/ios/icon-57-2x.png"         gap:platform="ios"        width="114" height="114" />
    <icon src="res/icon/ios/icon-72-2x.png"         gap:platform="ios"        width="144" height="144" />
    <icon src="res/icon/webos/icon-64.png"          gap:platform="webos" />
    <icon src="res/icon/windows-phone/icon-48.png"  gap:platform="winphone" />
    <icon src="res/icon/windows-phone/icon-173.png" gap:platform="winphone"   gap:role="background" />

    <!-- Define app splash screen for each platform. -->
    <gap:splash src="res/screen/android/screen-ldpi-portrait.png"  gap:platform="android" gap:density="ldpi" />
    <gap:splash src="res/screen/android/screen-mdpi-portrait.png"  gap:platform="android" gap:density="mdpi" />
    <gap:splash src="res/screen/android/screen-hdpi-portrait.png"  gap:platform="android" gap:density="hdpi" />
    <gap:splash src="res/screen/android/screen-xhdpi-portrait.png" gap:platform="android" gap:density="xhdpi" />
    <gap:splash src="res/screen/blackberry/screen-225.png"         gap:platform="blackberry" />
    <gap:splash src="res/screen/ios/screen-iphone-portrait.png"    gap:platform="ios"     width="320" height="480" />
    <gap:splash src="res/screen/ios/screen-iphone-portrait-2x.png" gap:platform="ios"     width="640" height="960" />
    <gap:splash src="res/screen/ios/screen-ipad-portrait.png"      gap:platform="ios"     width="768" height="1024" />
    <gap:splash src="res/screen/ios/screen-ipad-landscape.png"     gap:platform="ios"     width="1024" height="768" />
    <gap:splash src="res/screen/windows-phone/screen-portrait.jpg" gap:platform="winphone" />

    <!--
        Define access to external domains.

        <access />            - a blank access tag denies access to all external resources.
        <access origin="*" /> - a wildcard access tag allows access to all external resource.

        Otherwise, you can specify specific domains:
    -->
    <access origin="*"/> <!-- allow local pages -->
    <allow-navigation href="*" />
    <allow-intent href="*" />
    <!--
        <access origin="http://phonegap.com" />                    - allow any secure requests to http://phonegap.com/
        <access origin="http://phonegap.com" subdomains="true" />  - same as above, but including subdomains, such as http://build.phonegap.com/
        <access origin="http://phonegap.com" browserOnly="true" /> - only allows http://phonegap.com to be opened by the child browser.
    -->

   </widget>

in the androidmenifest.xml file , the permission is also given

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

解决方案

I am so Sorry, do you add Content-Security-Policy meta tag?if you set Content-Security-Policy meta incorrect,it may cause this problem.

这篇关于Cordova 5.0.0 android应用程序无法连接到互联网使用android 4.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆