android - 适用于 Android 2.2 但不适用于 Android 2.3

标签 android android-emulator android-manifest internet-connection

我制作了一个接受 xml 数据的应用程序,但是当我发送对该资源的查询时,看起来没有连接。我添加了 android 互联网权限并在浏览器中有网络,但在我的应用程序中没有任何连接。

这是代码

    protected String sendRequest(String urlAdr,ArrayList postVars){


        String data=extractPairValuesToString(postVars);
        urlAdr+=data; //send all variables in the url not from request properties
        String xmlResponse=null;
        HttpURLConnection con = null;
        URL url;


        try {
            url = new URL(urlAdr);
            con = (HttpURLConnection) url.openConnection();
            //con.setReadTimeout(10000 /* milliseconds */);
            //con.setConnectTimeout(15000 /* milliseconds */);
            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());
        }
    }

最佳答案

很多时候, list 丢失了:

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

看这里: http://developer.android.com/resources/tutorials/views/hello-webview.html

关于android - 适用于 Android 2.2 但不适用于 Android 2.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8624823/

相关文章:

android - 应用程序 UI 因 GC 消息而卡住

android - 我在 android studio 中遇到模拟器错误

android - 在android模拟器中模拟led手电筒?

android - 如何在vitamio中实现拖动seekbar时即时seek

android - 不使用 Firebase 用户 uid 的自定义 Firebase 用户身份

android - Gradle 根据构建风格交换 jniLibs 资源

Android 模拟器在一段时间后失去互联网连接

android - 应用程序 :transformClassesWithDexForDebug exception and java. util.concurrent.ExecutionException

android - 从/res 依赖中获取资源

android - 如何在 Android XML 中旋转线?