Sam R
Sam R

Reputation: 111

No ads show up with Real admob ad Unit Id

I have tried adding Admob ad to my app.When i use actual Ad unit Id no banner ad show up at the bottom in the layout. I had made Ad unit Id on 19 th june.Test Ads do show up in the layout when i use sample ad unit id. Let me know if you need any other info.

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {

    private AdView mAdView;

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_main);
        MobileAds.initialize(this, actualAppId);
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice("1FC8C6E02CD016F49544EADF9599F3FD")
                .build();
        mAdView.loadAd(adRequest);

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mAdView != null) {
            mAdView.resume();
        }
    }

    @Override
    protected void onDestroy() {
        if (mAdView != null) {
            mAdView.destroy();
        }
        super.onDestroy();
    }

    protected void onPause() {
        if (mAdView != null) {
            mAdView.pause();
        }
        super.onPause();
    }  
}

Upvotes: 0

Views: 411

Answers (1)

user8873209
user8873209

Reputation:

You need to add test device id if you are testing Ads even with real Ad unit Id. Device id will appear in logcat when you run app.

AdRequest adRequest = new AdRequest.Builder()
     .addTestDevice("YOUR_DEVICE_ID")
     .build();

Upvotes: 1

Related Questions