适用于 Android 2.2 但不适用于 Android 2.3
Posted
技术标签:
【中文标题】适用于 Android 2.2 但不适用于 Android 2.3【英文标题】:Works with Android 2.2 but not Android 2.3 【发布时间】:2012-01-27 07:56:45 【问题描述】:我制作了一个接受 xml 数据的应用程序,但是当我发送对该资源的查询时,看起来没有连接。我添加了 android 互联网权限并在浏览器中有网络,但在我的应用程序中没有任何连接。
这是代码
受保护的字符串发送请求(字符串 urlAdr,ArrayList postVars) 字符串数据=extractPairValuesToString(postVars); urlAdr+=数据; //发送url中的所有变量,而不是来自请求属性 字符串 xmlResponse=null; HttpURLConnection con = null; 网址网址; 尝试 url = 新 URL(urlAdr); con = (HttpURLConnection) url.openConnection(); //con.setReadTimeout(10000 /* 毫秒 */); //con.setConnectTimeout(15000 /* 毫秒 */); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); con.setRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Content-Length", ""+Integer.toString(data.getBytes().length)); con.setDoInput(true); con.setDoOutput(true); catch (IOException e) setErrorStatus(e.getMessage());【问题讨论】:
你有没有异常(除了 IOException 甚至 IOException)? 不,任何异常都不会出现 【参考方案1】:manifest 经常丢失:
<uses-permission android:name="android.permission.INTERNET"/>
请看这里: http://developer.android.com/resources/tutorials/views/hello-webview.html
【讨论】:
我在此处发布之前添加了这一行,我的应用程序使用此代码在 android 2.2 上运行,但在 android 2.3 上不运行, 您应该使用这些重要信息来编辑您的问题! “适用于 Android 2.2 但不适用于 Android 2.3” 同一个 2.3 模拟器默认情况下没有互联网连接应用程序,无论我是否包含互联网权限,例如发布使用权限。 可能是一些必须添加的东西,而不仅仅是权限。以上是关于适用于 Android 2.2 但不适用于 Android 2.3的主要内容,如果未能解决你的问题,请参考以下文章