开发者

admob connection refused

开发者 https://www.devze.com 2023-02-25 13:38 出处:网络
I\'m just getting started with adding admob to my android app and have started with using the banner essentials example that is available from the admob website.Here is the sample code.

I'm just getting started with adding admob to my android app and have started with using the banner essentials example that is available from the admob website. Here is the sample code.

public class BannerEssentials extends Activity{
  @Override
  public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Lookup R.layout.main
    LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);

    // Create the adView
    // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
    AdView adView = new AdView(this, AdSize.BANNER, "a14da528179106a");

    // Add the adView to it
    layout.addView(adView);

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    request.setTesting(true);

    adView.loadAd(request);            
  }
}

I've setup my account with admob and everything appears to be in place, when I look in my logCat I see the following connection refused error message for admob. Has anyone else experienced this problem and if so how did you resolve it? Thanks in advance for your help.

04-13 11:39:33.410: WARN/Ads(5662): java.net.ConnectException: r.admob.com/127.0.0.1:80 - Connection refused
04-13 11:39:33.410: WARN/Ads(5662):     at org.apache.harmony.luni.net.PlainSocketImpl.connect开发者_Python百科(PlainSocketImpl.java:254)
04-13 11:39:33.410: WARN/Ads(5662):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
04-13 11:39:33.410: WARN/Ads(5662):     at java.net.Socket.connect(Socket.java:1055)
04-13 11:39:33.410: WARN/Ads(5662):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
04-13 11:39:33.410: WARN/Ads(5662):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
04-13 11:39:33.410: WARN/Ads(5662):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
04-13 11:39:33.410: WARN/Ads(5662):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)
04-13 11:39:33.410: WARN/Ads(5662):     at b.a(Unknown Source)
04-13 11:39:33.410: WARN/Ads(5662):     at b.doInBackground(Unknown Source)
04-13 11:39:33.410: WARN/Ads(5662):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-13 11:39:33.410: WARN/Ads(5662):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-13 11:39:33.410: WARN/Ads(5662):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-13 11:39:33.410: WARN/Ads(5662):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-13 11:39:33.410: WARN/Ads(5662):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-13 11:39:33.410: WARN/Ads(5662):     at java.lang.Thread.run(Thread.java:1096)

My Manifest file below.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.google.ads.example"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".BannerEssentials"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <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"/> 
    <uses-sdk android:minSdkVersion="3" />

</manifest> 


How is your manifest set up? Did you add the Internet permission? Did you set the appropriate metadata parameters?


Update: I found the source of my problem. I have a rooted phone from which I have the ability to disable ads to display. (I know, what was I thinking?) Anyway as soon as I disabled that feature ads are working just fine on my app. Hope this helps someone else.


You didn't add (Internet, Access Internet) permission nor metadata.

Check out the guide to use ads go: https://developers.google.com/admob/android/quick-start

If you're facing any problems with that guide check out the following video: the following video

0

精彩评论

暂无评论...
验证码 换一张
取 消