AdMob After Ad receive - IOException connecting to ad url

房东的猫 提交于 2019-12-19 09:53:26

问题


i have an android app that need to show ads by AdMob. here's my Log:

07-18 01:55:53.116: INFO/Ads(8682): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":0,"u_sd":1.5,"slotname":"**************","u_w":320,"msid":"com.paladin.hilula","cap":"m","adtest":"on","js":"afma-sdk-a-v4.1.0","isu":"*********************************","format":"320x50_mb","net":"ed","app_name":"1.android.com.paladin.hilula","hl":"hd","u_h":569,"testing":1,"u_audio":1,"u_so":"p"});</script></head><body></body></html>
07-18 01:55:54.187: INFO/Ads(8682): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?preqs=0&u_sd=1.5&slotname=**************&u_w=320&msid=com.paladin.hilula&cap=m&adtest=on&js=afma-sdk-a-v4.1.0&isu=*************************&format=320x50_mb&net=ed&app_name=1.android.com.paladin.hilula&hl=hd&u_h=569&testing=1&u_audio=1&u_so=p&output=html&region=mobile_app&u_tz=-180&ex=1&client_sdk=1", "afmaNotifyDt": "null">
07-18 01:56:15.288: WARN/Ads(8682): IOException connecting to ad url.
07-18 01:56:15.288: WARN/Ads(8682): java.net.SocketTimeoutException: Connection timed out
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
07-18 01:56:15.288: WARN/Ads(8682):     at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:204)
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
07-18 01:56:15.288: WARN/Ads(8682):     at java.net.Socket.connect(Socket.java:983)
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
07-18 01:56:15.288: WARN/Ads(8682):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
07-18 01:56:15.288: WARN/Ads(8682):     at b.a(Unknown Source)
07-18 01:56:15.288: WARN/Ads(8682):     at b.doInBackground(Unknown Source)
07-18 01:56:15.288: WARN/Ads(8682):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-18 01:56:15.288: WARN/Ads(8682):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-18 01:56:15.288: WARN/Ads(8682):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-18 01:56:15.288: WARN/Ads(8682):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-18 01:56:15.288: WARN/Ads(8682):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-18 01:56:15.288: WARN/Ads(8682):     at java.lang.Thread.run(Thread.java:1019)
07-18 01:56:15.296: INFO/Ads(8682): onFailedToReceiveAd(A network error occurred.)

i get the URL but cant show it.

in manifest:

    <activity android:name="com.google.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation"/>
  </application>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

in .java:

    // Create the adView
    AdView adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
    // Lookup your LinearLayout assuming it’s been given
    // the attribute android:id="@+id/mainLayout"
    RelativeLayout layout = (RelativeLayout)findViewById(R.id.rlayout);
    // Add the adView to it
    layout.addView(adView);
    // Initiate a generic request to load it with an ad
    AdRequest r = new AdRequest();
    r.setTesting(true);
    r.addTestDevice("*****************************");

    adView.loadAd(r);

回答1:


The /etc/hosts file on your phone has aliased r.admob.com to 127.0.0.1. I had this occur when I used a flashed ROM on my phone -- the ROM defined a whole bunch of entries like that so I'd never get ads. Which was great until I was testing my own ad-enabled app :-)

Edit your /etc/hosts and take out that entry.




回答2:


AdMob's server (like any high volume server) can take too long to respond sometimes. It is better that you design with failure like this as expected behavior.

If you think there is more to it than that. Post what you are seeing that makes you think something else may be going on.



来源:https://stackoverflow.com/questions/6727369/admob-after-ad-receive-ioexception-connecting-to-ad-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!