android – 如果我的应用程序在API 8模拟器上运行,则Internet连接无法正常工作

android – 如果我的应用程序在API 8模拟器上运行,则Internet连接无法正常工作,第1张

概述嗨,谢谢你的帮助, 我有一个应用程序,我在 Eclipse中针对API 17进行编译. 该应用程序执行一些简单的Internet连接. 现在,当我在使用API​​ 17的仿真器上进行测试时,一切正常. 如果我使用API​​ 8对模拟器进行测试,那么App显然无法执行网络连接(adMob dos显示,HttpGet显然没有检索任何东西……)从我的应用程序(模拟器上的Web浏览器工作正常并正常加载). 嗨,谢谢你的帮助,
我有一个应用程序,我在 Eclipse中针对API 17进行编译.

该应用程序执行一些简单的Internet连接.

现在,当我在使用API​​ 17的仿真器上进行测试时,一切正常.

如果我使用API​​ 8对模拟器进行测试,那么App显然无法执行网络连接(adMob dos显示,httpGet显然没有检索任何东西……)从我的应用程序(模拟器上的Web浏览器工作正常并正常加载).

并且adMob也不会加载到具有API 8或10的仿真器(它在API 17仿真器上).

非常感谢任何帮助!

这是我的主要活动:

public class QuotesActivity extends Activity implements MyInterface {private String url2;public static ArrayList<Stock> lt;public static ArrayList<Stock> favQ;public MyAdapter myAdap;public Intent intent;public ListVIEw lv;public FavManager fm;private AdVIEw adVIEw;@OverrIDepublic voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.search);    AdRequest request = new AdRequest();    // request.addTestDevice(AdRequest.TEST_EMulATOR);    request.setGender(AdRequest.Gender.MALE);    boolean tabletSize = getResources().getBoolean(R.bool.istablet);    if (tabletSize) {        // Create the adVIEw        adVIEw = new AdVIEw(this,AdSize.SMART_BANNER,"a151388079e47d1");    } else {        // Create the adVIEw        adVIEw = new AdVIEw(this,AdSize.BANNER,"a151388079e47d1");    }    // Lookup your linearLayout assuming it's been given    // the attribute androID:ID="@+ID/mainLayout"    linearLayout layout = (linearLayout) findVIEwByID(R.ID.ad);    // Add the adVIEw to it    layout.addVIEw(adVIEw);    // Initiate a generic request to load it with an ad    adVIEw.loadAd(request);    lt = new ArrayList<Stock>();    favQ = new ArrayList<Stock>();    fm = new FavManager(getApplicationContext());    favQ.clear();    favQ.addAll(fm.ritiraFav());    PreferenceManager.setDefaultValues(this,R.xml.preferences,false);    lt.clear();    // ////////////    try {        inputStream in = getResources().openRawResource(R.raw.markets3);        if (in != null) {            inputStreamReader tmp = new inputStreamReader(in);            BufferedReader reader = new BufferedReader(tmp);            String str;            String str1 = null;            String str2 = null;            boolean flag = true;            while ((str = reader.readline()) != null) {                if (flag) {                    str1 = str;                    flag = false;                } else {                    str2 = str;                    lt.add(new Stock(str1,str2,"0","0"));                    flag = true;                }            }            in.close();        }    }    catch (Throwable t) {        // Log.e("","Exception: " + t.toString());    }    // ///////    Collections.sort(lt,new Comparator<Stock>() {        public int compare(Stock s1,Stock s2) {            return s1.nome.comparetoIgnoreCase(s2.nome);        }    });    lv = (ListVIEw) findVIEwByID(androID.R.ID.List);    lv.setScrollbarFadingEnabled(false);    button favourites = (button) findVIEwByID(R.ID.favoritesbtn);    favourites.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            Intent intent = new Intent(QuotesActivity.this,QuotesActivityFavourites.class);            startActivity(intent);        }    });    button search = (button) findVIEwByID(R.ID.googsearch);    search.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            // Log.e("","Chiamo onSearchRequested()");            onSearchRequested();        }    });    myAdap = new MyAdapter(lt,this,this);    myAdap.l = lt;    lv.setAdapter(myAdap);    button preference = (button) findVIEwByID(R.ID.preferencebutton);    preference.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            Intent intent = new Intent(QuotesActivity.this,SettingsActivity.class);            startActivity(intent);        }    });    lv.setonItemClickListener(new OnItemClickListener() {        public voID onItemClick(AdapterVIEw<?> parent,VIEw vIEw,final int position,long ID) {            for (Stock item : favQ) {                if (item.simbolo.equals(lt.get(position).simbolo)) {                    AlertDialog.Builder builder = new AlertDialog.Builder(                            QuotesActivity.this);                    builder.setPositivebutton("Yes",new OnClickListener() {                        public voID onClick(DialogInterface arg0,int arg1) {                            deleteFromFavorites(lt.get(position));                        }                    });                    builder.setNegativebutton("No",int arg1) {                            // Quotes.layoutSchermo(2);                        }                    });                    builder.setMessage("Stock Already in Portfolio. Delete from it?");                    builder.setTitle(lt.get(position).nome);                    AlertDialog dialog = builder.create();                    builder.show();                    return;                }            }            AlertDialog.Builder builder = new AlertDialog.Builder(                    QuotesActivity.this);            final int pos = position;            builder.setPositivebutton("Yes",new OnClickListener() {                public voID onClick(DialogInterface arg0,int arg1) {                    addToFavorites(lt.get(pos));                }            });            builder.setNegativebutton("No",int arg1) {                    // Quotes.layoutSchermo(2);                }            });            builder.setMessage("Add to Portfolio?");            builder.setTitle(lt.get(position).nome);            AlertDialog dialog = builder.create();            builder.show();            // dialog.show();        }    });}@OverrIDepublic voID onResume() {    super.onResume();    relativeLayout focuslayout = (relativeLayout) findVIEwByID(R.ID.RequestFocusLayout);    focuslayout.requestFocus();    favQ.clear();    favQ.addAll(fm.ritiraFav());}public voID addToFavorites(final Stock toadd) {    fm.addFav(toadd);    favQ.clear();    favQ.addAll(fm.ritiraFav());    return;}public voID deleteFromFavorites(Stock todel) {    fm.removeFav(todel);    favQ.clear();    favQ.addAll(fm.ritiraFav());    return;}public voID Updateline(Integer position) {    UpdateTask up = new UpdateTask();    up.execute(position,null,null);}public class UpdateTask extends AsyncTask<Integer,VoID,VoID> {    @OverrIDe    protected voID onProgressUpdate(VoID... progress) {    }    @OverrIDe    protected voID onPostExecute(VoID result) {        myAdap.l = lt;        myAdap.notifyDataSetChanged();    }    @OverrIDe    protected VoID doInBackground(Integer... position) {        DefaulthttpClIEnt clIEnt = new DefaulthttpClIEnt();        String srt = "";        // ///////////API SEGReto DI Google ORIGINARIO        // String url        // =getString(R.string.dettaglio1).concat("'"+fav.get(i).simbolo+"'").concat(getString(R.string.dettaglio2));        // ///////////API ALTERNATIVO        String url = getString(R.string.urlaternativo).concat(                lt.get(position[0]).simbolo);        httpGet getmethod = new httpGet(url);        try {            ResponseHandler<String> responseHandler = new BasicResponseHandler();            srt = clIEnt.execute(getmethod,responseHandler);            int inizio = srt.indexOf("<last data=\"");            int fine = srt.indexOf("\"/>",inizio + 12);            lt.get(position[0]).setPrezzo(srt.substring(inizio + 12,fine));            inizio = srt.indexOf("<perc_change data=\"");            fine = srt.indexOf("\"/>",inizio + 19);            lt.get(position[0]).setCambiamento(                    srt.substring(inizio + 19,fine));        } catch (Throwable t) {            // Log.e("ERRORE INTERNET","ERRORE INTERNET",t);        }        return null;    }}@OverrIDepublic voID onDestroy() {    if (adVIEw != null) {        adVIEw.destroy();    }    super.onDestroy();}}

这是我的清单:

<manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"package="com.example.quotes" ><uses-sdk    androID:minSdkVersion="8"    androID:targetSdkVersion="17" /><uses-permission androID:name="androID.permission.INTERNET" /><uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE" /><application androID:deBUGgable="true" >    <activity        androID:name=".QuotesActivity"        androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize"        androID:icon="@drawable/ic_launcher"        androID:label="Markets in your pocket !" >        <intent-filter>            <action androID:name="androID.intent.action.MAIN" />            <category androID:name="androID.intent.category.LAUNCHER" />        </intent-filter>        <Meta-data            androID:name="androID.app.default_searchable"            androID:value=".QuotesActivitySearch" />    </activity>    <activity        androID:name=".QuotesActivitySearch"        androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize"        androID:icon="@drawable/ic_launcher"        androID:label="Markets in your pocket !" >        <intent-filter>            <action androID:name="androID.intent.action.SEARCH" />        </intent-filter>        <Meta-data            androID:name="androID.app.searchable"            androID:resource="@xml/searchable" />    </activity>    <activity        androID:name=".QuotesActivityFavourites"        androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize"        androID:icon="@drawable/ic_launcher"        androID:label="Markets in your pocket !" >    </activity>    <activity        androID:name=".SettingsActivity"        androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize"        androID:label="Settings" >    </activity>    <activity        androID:name="com.Google.ads.AdActivity"        androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize" /></application>

这是我的LogCat:

03-15 14:16:05.554: D/dalvikvm(1466): GC_EXPliCIT freed 909K,43% free 4716K/8135K,external 1170K/1682K,paused 7ms03-15 14:16:07.185: E/ActivityThread(1466): Failed to find provIDer info for    com.Google.plus.platform03-15 14:16:07.185: D/szipinf(1466): Initializing inflate state03-15 14:16:07.185: D/szipinf(1466): Initializing zlib to inflate03-15 14:16:07.214: I/Ads(1466): To get test ads on this device,call    adRequest.addTestDevice("6EA1DCF3A944D7B947BC304C7A9E933D");03-15 14:16:07.268: D/dalvikvm(1466): GC_CONCURRENT freed 395K,36% free 5315K/8263K,external 1121K/1603K,paused 1ms+0ms03-15 14:16:07.290: I/Ads(1466): adRequestUrlHTML: <HTML><head><script     src="http://media.admob.com/sdk-core-v40.Js"></script>   <script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":3,"session_ID":"1145804483122245265 2","seq_num":"4","slotname":"a151388079e47d1","u_w":320,"msID":"com.marketsinyourpocket","cap":"m,a","Js":"afma-sdk-a-    v6.3.0","bas_off":0,"net":"ed","app_name":"1.androID.com.marketsinyourpocket","hl":"en","gnt":3,"cust_gender":1,"carrIEr":"310260","u_audio":1,"u_sd":1.5,"ms":"Qqlgt9Kwv7BZOnio6PfLHi5mVs5ayp77VGIIyJ3Y7sojTNwIZfi0LHn2PZquoJTqpJx8NtOvTzGKWYlbxvU8fOjXkArCoqoQnGrLKZ57CTZOOt2WWrL9k8pyN4P-nBwIvuZDvijR0reHDyhcqwAoMtPdOeUV_cwIE3jk-6BMm_IgvGs8EKWVZESeqrSuExAStQMMsUYcC6p-XkB8KegxEX4FS2Q2CibdMk3CMKoAzfF58Sxp6DvRObm662IVwImzFWGdQ22UVx4ViQqz_ensdg1bXk5jgpyBOpV0jMFHgoEv5SwD5zpoeJfo-a1f0d5GR35f2bDAb3iXucuGB723lA","isu":"6EA1DCF3A944D7B947BC304C7A9E933D","format":"320x50_mb","oar":0,"ad_pos":{"height":0,"visible":0,"y":0,"x":0,"wIDth":0},"u_h":533,"pt":1,"bas_on":0,"ptime":143736});</script></head><body></body></HTML>03-15 14:16:07.358: W/webcore(1466): Can't get the vIEwWIDth after the first layout03-15 14:16:07.448: D/dalvikvm(1466): GC_CONCURRENT freed 338K,33% free 6141K/9031K,paused 1ms+0ms03-15 14:16:13.494: V/URL I USE(1466): http://www.Google.com/ig/API?stock=SHY03-15 14:16:33.614: E/EXCEPTION I GET(1466): java.net.UnkNownHostException: www.Google.com

编辑编辑编辑

甚至在API 10英特尔加速仿真器上尝试过,没有更好的运气

代理设置正确,

数据传输已启用

……我有点绝望了!

编辑编辑

发布整个活动

编辑编辑

该应用程序在使用API​​ 10的真实电话上正常工作(不在我的模拟器上使用API​​ 10)!

我抓到的错误是

03-15 13:14:43.299: E/Exception(1318): java.net.UnkNownHostException: www.Google.com

我确实使用Google REST服务

谢谢你的帮助!

解决方法 我很确定这是代理设置问题.尝试显式设置代理(从AndroID系统获取值).

在默认的httpClIEnt上,这将是:

httpClIEnt clIEnt = new DefaulthttpClIEnt();//Get the default settings from APN  String proxyHost = androID.net.Proxy.getDefaultHost();  int proxyPort = androID.net.Proxy.getDefaultPort();//Set Proxy params of clIEnt,if they are not the standard    if (proxyHost != null && proxyPort > 0) {        httpHost proxy = new httpHost(proxyHost,proxyPort);        clIEnt.getParams().setParameter(ConnRoutePnames.DEFAulT_PROXY,proxy);    }httpGet request = new httpGet("http://www.Google.com");
@H_301_80@ 总结

以上是内存溢出为你收集整理的android – 如果我的应用程序在API 8模拟器上运行,则Internet连接无法正常工作全部内容,希望文章能够帮你解决android – 如果我的应用程序在API 8模拟器上运行,则Internet连接无法正常工作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1121997.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存