简体   繁体   中英

How to create a banner ad with admob and android studio

I've Tried to run ad with my App ID and Ad unit id ,it didn't show anything but when I used sample App ID and Ad unit id it shows sample ads.

sample Ad unit ID: ca-app-pub-3940256099942544/6300978111

sample App ID: ca-app-pub-3940256099942544~3347511713

my Ad unit ID: ca-app-pub-3034909524223644/38127934

my App ID: ca-app-pub-3034909524223644~23360602

I've used this ad unit id in an old application and it working what should i do?

AndroidManifest.xml

       <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-3034909524223644~2336060216" />

        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />

Layout.xml

 <com.google.android.gms.ads.AdView
                    android:id="@+id/adView"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    ads:adSize="BANNER"
                    ads:adUnitId="ca-app-pub-3034909524223644/3812793416" />

Main


@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.fragment_home, container, false);


        AdView adView = (AdView) view.findViewById(R.id.adView);
        runAds(adView);

        return view;
    }

 protected void runAds(AdView adView){
      AdRequest adRequest = new AdRequest.Builder()
              .setRequestAgent("android_studio:ad_template").build();
      adView.loadAd(adRequest);
  }

dependencies

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.+'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:26.0.+'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
    implementation 'com.google.android.gms:play-services-ads:17.1.1'

}

If you just created you ads id, it may happen. Ads normally take 5 to 24 hours to show after creation of ad id.

I had the same issue. your Ad unit id will not show live Ads till your app is live. Test ad will show only test ads. I had recently uploaded one app which is showing live ads after I roll-out app to the Beta-release .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM