문제

I developed app for version 2.3 ,it uses web service to authenticate device users;same app when I deployed in Samsung GT-P3100 (version4.0.3 Icecream Sandwitch ) I get connection failure;though the device I can communicate to webservice using browser...please suggest ,do I need to recreate the project for version 4.0.3 or does tab requires some special permission in mainfest file?..what could be the possible cause

올바른 솔루션이 없습니다

다른 팁

Use this code for get the html content:

public static String getHTML ( String url) throws IOException { 
            if (url == null || url.length() == 0) { 
                    throw new IllegalArgumentException("url cannot be null or empty"); 
            } 
            final HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); 
            final BufferedReader buf = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
            final StringBuilder page = new StringBuilder(); 
            final String lineEnd = System.getProperty("line.separator"); 
            String line; 
            try { 
                    while (true) { 
                            line = buf.readLine(); 
                            if (line == null) { 
                                    break; 
                            } 
                            page.append(line).append(lineEnd); 
                    } 
            } finally { 
                    buf.close(); 
            } 

            try {
                    return page.toString().substring(0, page.toString().length() -1);
            } catch (Exception e) {
                    return "";
            }

    }

you need add the permision in AndroidManifest.xml

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

maybe on android 4 and heighter you need to perform this function in a new thread, for that use the code:

startInNewThread();

//call the fonction getHTML() in a new thread
private void startInNewThread() {

            new Thread(new Runnable() {
                    @Override
                    public void run() {
                          getHTML ("URL");

                    }
            }).start();
    }

After if you need to update UI with the result of "getHtml()" you must to create a Handler

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top