0

I added Admob banner to my app and it works well.

The code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Load an ad into the AdMob banner view.
    AdView adView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .setRequestAgent("android_studio:ad_template").build();
    adView.loadAd(adRequest);
}

xml:

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    ads:adSize="BANNER"
    ads:adUnitId="xxxxxx-xxxxx" />

I want to change ads:adUnitId from mainactivity.

an example if a==1 ads:adUnitId = xxxxxxx else ads:adUnitId=yyyyyyy

How can I do that?

Thanks.

tripleee
  • 175,061
  • 34
  • 275
  • 318
michaelzX
  • 13
  • 1
  • 5
  • adView.setAdUnitId(AD_UNIT_ID) ; then AdRequest adRequest = new AdRequest.Builder() .setRequestAgent("android_studio:ad_template").build(); adView.loadAd(adRequest); – Shubham Jain Sep 27 '17 at 17:14
  • I have tried it but not work. The app crashed. – michaelzX Sep 27 '17 at 17:24
  • share the crash log – Shubham Jain Sep 27 '17 at 17:27
  • @ShubhamJain E/GooglePlayServicesUtil: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. – michaelzX Sep 27 '17 at 17:41
  • for the shared log please visit https://stackoverflow.com/q/18068627/4853552 – Shubham Jain Sep 27 '17 at 17:45
  • @ShubhamJain admob banner is already working in my app. – michaelzX Sep 27 '17 at 17:53
  • Please do not vandalize your posts. Once you've posted a question, it belongs to the Stack Overflow community at large (under the CC-by-SA license). If you would like to disassociate this post from your account, see [What is the proper route for a disassociation request?](https://meta.stackoverflow.com/questions/323395/what-is-the-proper-route-for-a-dissociation-request) – tripleee Oct 09 '17 at 04:19

0 Answers0