问题
Good time of a day. I have a problem. I need to test admob functionality in my app, but my phone can't displaying any admob ads. Here the log from Logcat when ads tries to load:
12-11 14:32:07.375: I/Ads(21029): Received ad url: <"url": "http://googleads.g.doubleclick.net:80/mads/gma?preqs=6&u_sd=1.5&slotname=a14ec2c281ec768&u_h=533&u_w=320&msid=com.academy.tarot.divinations.m&js=afma-sdk-a-v4.1.1&isu=766D9982A610C2807FBA0F6C480742E4&format=320x50_mb&net=wi&app_name=15.android.com.academy.tarot.divinations.m&u_audio=1&hl=en&u_so=p&output=html®ion=mobile_app&u_tz=-240&ex=1&client_sdk=1&askip=1", "afmaNotifyDt": "null">
12-11 14:32:07.378: W/Ads(21029): IOException connecting to ad url.
12-11 14:32:07.378: W/Ads(21029): java.net.ConnectException: googleads.g.doubleclick.net/127.0.0.1:80 - Connection refused
12-11 14:32:07.378: W/Ads(21029): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207)
12-11 14:32:07.378: W/Ads(21029): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
12-11 14:32:07.378: W/Ads(21029): at java.net.Socket.connect(Socket.java:1002)
12-11 14:32:07.378: W/Ads(21029): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
12-11 14:32:07.378: W/Ads(21029): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
12-11 14:32:07.378: W/Ads(21029): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
12-11 14:32:07.378: W/Ads(21029): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
12-11 14:32:07.378: W/Ads(21029): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
12-11 14:32:07.378: W/Ads(21029): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
12-11 14:32:07.378: W/Ads(21029): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
12-11 14:32:07.378: W/Ads(21029): at b.run(Unknown Source)
12-11 14:32:07.378: W/Ads(21029): at java.lang.Thread.run(Thread.java:1019)
12-11 14:32:07.378: D/webviewglue(21029): nativeDestroy view: 0x2dbe88
12-11 14:32:07.378: I/Ads(21029): onFailedToReceiveAd(A network error occurred.)
And this error is occuring in any time in any apps. I don't have any AdsFree apps. Internet is online and works fine. What I can do to solve that problem?
回答1:
You are testing this on a device with a changed hostfile, that blocks doubleclick requests:
java.net.ConnectException: googleads.g.doubleclick.net/127.0.0.1:80 - Connection refused
doubleclick.net points to the ip 127.0.0.1:80, which is your own IP. If you are doing this on a computer with the emulator, try and find the hosts* file, and remove the line about doubleclick.
This is a common thing ad-filters and 'tracking cookie' blockers do for you. If you have installed any "add filtering" on your phone (possibly a rooted-phone only action), or changed the hosts file, it would be the same problem obviously
* you can find some hints here of where it is located: http://en.wikipedia.org/wiki/Hosts_(file)
For winodws it would **%SystemRoot%\system32\drivers\etc\hosts**
回答2:
Your /etc/hosts file has re-defined r.admob.com to 127.0.0.1 -- custom ROMs that you download from various sources all do that, because it blocks out all the ads. Edit your /etc/hosts file and take out that entry.
来源:https://stackoverflow.com/questions/8463376/why-admob-ads-in-any-apps-not-displaying