簡體   English   中英

Android模擬器互聯網連接問題-真實設備正常工作。

[英]Android emulator internet connection issues - real device works.

我正在嘗試從網站獲取JSON格式的文本。 它可以在我真正的智能手機上完美運行,但不能在Android Emulator(4.0.3)中運行。 檢查互聯網連接是否正常:

ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected())
            return true;
        else
            return false;

這給我的模擬器一個空的結果,但是我在手機中得到了一些東西:

HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(new HttpGet(url));

    inputStream = httpResponse.getEntity().getContent();
        if (inputStream != null)
            result = convertInputStreamToString(inputStream);

通讀此書,它應該可以解決您的問題:

http://www.gitshah.com/2011/02/android-fixing-no-internet-connection.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM