PhoneGap的Andr​​oid的上网不工作 [英] Phonegap Android internet not working

查看:153
本文介绍了PhoneGap的Andr​​oid的上网不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写我的PhoneGap的第一个应用程序,我一直在Android设备上测试。我相信我已授予相应的权限:

 <使用许可权的android:NAME =android.permission.INTERNET对/>

但地图没有显示出来。我试图从一个Web服务的经度和纬度,并用它来把国旗的谷歌地图。我相信这个问题实际上是与互联网接入,好像我这运行通过Visual Studio作为一个网站,服务返回的坐标,并显示在地图。然而,当应用程序被编译和网站运行应用程序的WebView不返回的坐标内,地图没有显示。

我还添加了一个表格,显示返回的坐标,他们再次显示在浏览器中,但在运行应用程序的空白。没有人有任何想法,为什么会的WebView不能够连接到互联网,并返回所需的数据?我已删除了Web服务的实际地址,但我知道这是好的,因为它工作在一个浏览器。

HTML页:

 <!DOCTYPE HTML>
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
  < HEAD>
    <标题>< /标题>
    <脚本类型=文/ JavaScript的SRC =htt​​ps://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true>< / SCRIPT>
    <链接rel =stylesheet属性类型=文/ CSS的href =CSS / index.css/>
  < /头>
  <身体GT;
    < D​​IV CLASS =APP2>
      < D​​IV ID =地图的风格=宽度:200像素,高度:150像素>< / DIV>
      <脚本类型=文/ JavaScript的>
        VAR XMLHTTP =新XMLHtt prequest();
        xmlhttp.open(GET,http://www.xxxxxxxx.com/mobile/iphone/xml/postal.asp?postal=33173,FALSE);
        xmlhttp.send();
        xmlDoc中= xmlhttp.responseXML;
        VAR myOptions = {
          变焦:10,
          mapTypeId设为:google.maps.MapTypeId.ROADMAP,
        };
        VAR地图=新google.maps.Map(的document.getElementById(地图),myOptions);
        变种纬度= X [i]于.getElementsByTagName(纬度)[0] .childNodes [0] .nodeValue;
        变种长= X [i]于.getElementsByTagName(经度)[0] .childNodes [0] .nodeValue;
        VAR POS =新google.maps.LatLng(纬度,经度);
        VAR信息窗口=新google.maps.InfoWindow({
          地图:地图,
          位置:POS机,
          内容:邮报code 33173(纬度:+纬度+,长:+长+)
        });
        map.setCenter(POS)
      < / SCRIPT>
      <脚本>
        的document.write(<表边框='1'>中);
        document.write(\"<tr><td>Post$c$c</td><td>latitude</td><td>longitude</td></tr>\");
        VAR X = xmlDoc.getElementsByTagName(位置);
        对于(i = 0; I&LT; x.length;我++){
          的document.write(&所述; TR&GT;&下; TD&GT; 33173&下; / TD&GT;&下; TD&gt;中);
          的document.write(X [I] .getElementsByTagName(纬度)[0] .childNodes [0] .nodeValue);
          的document.write(&下; / TD&GT;&下; TD&gt;中);
          的document.write(X [i]于.getElementsByTagName(经度)[0] .childNodes [0] .nodeValue);
          文件撰写(&下; / TD&GT;&下; / TR&gt;中);
        }
        文件撰写(&LT; /表&gt;);
      &LT; / SCRIPT&GT;
    &LT; / DIV&GT;
  &LT; /身体GT;
&LT; / HTML&GT;

清单:

 &LT; XML版本='1.0'编码='UTF-8'&GT?;
&LT;表明机器人:hardwareAccelerated =真正的安卓版code =1机器人:=的versionName1.0.0机器人:windowSoftInputMode =adjustPan包=dig.phonegap.loa_app的xmlns:机器人= http://schemas.android.com/apk/res/android\">
  &LT;支持屏安卓anyDensity =真正的机器人:largeScreens =真正的机器人:normalScreens =真正的机器人:调整大小=真正的机器人:smallScreens =真正的机器人:xlargeScreens =真/&GT;
  &LT;使用许可权的android:NAME =android.permission.CAMERA/&GT;
  &LT;使用许可权的android:NAME =android.permission.VIBRATE/&GT;
  &LT;使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/&GT;
  &LT;使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/&GT;
  &LT;使用许可权的android:NAME =android.permission.ACCESS_LOCATION_EXTRA_COMMANDS/&GT;
  &LT;使用许可权的android:NAME =android.permission.READ_PHONE_STATE/&GT;
  &LT;使用许可权的android:NAME =android.permission.INTERNET对/&GT;
  &LT;使用许可权的android:NAME =android.permission.RECEIVE_SMS/&GT;
  &LT;使用许可权的android:NAME =android.permission.RECORD_AUDIO/&GT;
  &LT;使用许可权的android:NAME =android.permission.MODIFY_AUDIO_SETTINGS/&GT;
  &LT;使用许可权的android:NAME =android.permission.READ_CONTACTS/&GT;
  &LT;使用许可权的android:NAME =android.permission.WRITE_CONTACTS/&GT;
  &LT;使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/&GT;
  &LT;使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/&GT;
  &LT;使用许可权的android:NAME =android.permission.GET_ACCOUNTS/&GT;
  &LT;使用许可权的android:NAME =android.permission.BROADCAST_STICKY/&GT;
  &LT;采用-SDK安卓的minSdkVersion =10机器人:targetSdkVersion =18/&GT;
  &lt;应用机器人:allowBackup =假
    机器人:hardwareAccelerated =真
    机器人:图标=@绘制/图标
    机器人:标签=@字符串/ APP_NAME&GT;
  &LT;活动机器人:configChanges =方向| keyboardHidden |键盘|屏幕尺寸|区域
    机器人:标签=@字符串/ APP_NAME
    机器人:名字=的HelloWorld
    机器人:主题=@安卓风格/ Theme.Black.NoTitleBar&GT;
  &所述;意图滤光器&gt;
    &lt;作用机器人:名字=android.intent.action.MAIN/&GT;
    &LT;类机器人:名字=android.intent.category.LAUNCHER/&GT;
  &所述; /意图滤光器&gt;
&LT; /活性GT;
&LT; /用途&gt;
&LT; /清单&GT;


解决方案

试试这个关于 config.xml中

者平台 - > Android的 - >水库 - > XML - > config.xml中

者平台 - > IOS - > config.xml中

者平台 - > WP7 - > config.xml中

者平台 - > WP8 - > config.xml中

 &LT;获得原产=*/&GT;

I am writing my first app in Phonegap and I have been testing it on an Android device. I believe I have granted the appropriate permission:

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

But the map is not showing up. I am trying to get a latitude and longitude from a web service and use this to put a flag on a Google map. I believe the issue is actually with the internet access, as if I run this through Visual Studio as a website, the service returns the coordinates and the map is displayed. However, when the app is compiled and that website is run inside the app webview the coordinates are not returned and no map is displayed.

I also added a table to show the returned coordinates, again they are displayed in a browser but are blank in the running app. Does anyone have any idea why the webview wouldn't be able to connect to the internet and return the required data? I have removed the actual address of the web service but I know that is fine as it works in a browser.

HTML page:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=true"></script>
    <link rel="stylesheet" type="text/css" href="css/index.css" />
  </head>
  <body>
    <div class="app2">
      <div id="map" style="width: 200px; height: 150px"></div>
      <script type="text/javascript">
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open("GET", "http://www.xxxxxxxx.com/mobile/iphone/xml/postal.asp?postal=33173", false);
        xmlhttp.send();
        xmlDoc = xmlhttp.responseXML;
        var myOptions = {
          zoom: 10,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
        };
        var map = new google.maps.Map(document.getElementById("map"), myOptions);
        var lat = x[i].getElementsByTagName("latitude")[0].childNodes[0].nodeValue;
        var long = x[i].getElementsByTagName("longitude")[0].childNodes[0].nodeValue;
        var pos = new google.maps.LatLng(lat, long);
        var infowindow = new google.maps.InfoWindow({
          map: map,
          position: pos,
          content: "Postcode 33173(Lat:" + lat + ", Long:" + long + ")"
        });
        map.setCenter(pos);
      </script>
      <script>
        document.write("<table border='1'>");
        document.write("<tr><td>Postcode</td><td>latitude</td><td>longitude</td></tr>");
        var x = xmlDoc.getElementsByTagName("position");
        for (i = 0; i < x.length; i++) {
          document.write("<tr><td>33173</td><td>");
          document.write(x[i].getElementsByTagName("latitude")[0].childNodes[0].nodeValue);
          document.write("</td><td>");
          document.write(x[i].getElementsByTagName("longitude")[0].childNodes[0].nodeValue);
          document.write("</td></tr>");
        }
        document.write("</table>");
      </script>
    </div>
  </body>
</html>

Manifest:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="1.0.0" android:windowSoftInputMode="adjustPan" package="dig.phonegap.loa_app" xmlns:android="http://schemas.android.com/apk/res/android">
  <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.CAMERA" />
  <uses-permission android:name="android.permission.VIBRATE" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.RECEIVE_SMS" />
  <uses-permission android:name="android.permission.RECORD_AUDIO" />
  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
  <uses-permission android:name="android.permission.READ_CONTACTS" />
  <uses-permission android:name="android.permission.WRITE_CONTACTS" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  <uses-permission android:name="android.permission.BROADCAST_STICKY" />
  <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="18" />
  <application android:allowBackup="false"
    android:hardwareAccelerated="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name">
  <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
    android:label="@string/app_name"
    android:name="HelloWorld"
    android:theme="@android:style/Theme.Black.NoTitleBar">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>
</application>
</manifest>

解决方案

Try this on config.xml:

Plaform -> android -> res -> xml -> config.xml

Plaform -> ios -> config.xml

Plaform -> wp7 -> config.xml

Plaform -> wp8 -> config.xml

<access origin="*" />

这篇关于PhoneGap的Andr​​oid的上网不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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