top of page
Suche

Advertisement with Google Admob - The easy way

  • Autorenbild: APPs SMF
    APPs SMF
  • 14. Aug. 2017
  • 2 Min. Lesezeit

I have figured out a quick step by step procedure to implement "smart banners" into our Apps. There are two “sides” on which you have to work. See below:

1. Google Admob:

  • Create an account at Google Admob. Just follow the instructions.

  • Add a new App at Admob. It’s OK to say that you didn't publish the App yet. You can link it later. No worries, you cannot do something wrong since you can always delete everything without any problem and start again.

  • Give an App-Name and the platform. In our case it’s Android. The Banner Name will be asked later. Here it’s the App name since one App can have few banners.

  • Choose smart banner. Text and image for advertisement is recommended.

  • At the end you get the ID for you advertisement in the form of “ca-app-pub-9336898352641187/2817469950”. Don't swap it with the App-ID which is very similar. Both start with the same numbers. The Advertisement-ID has a "/" within the number.

2. In the App (Android Studio)

  • Start with adding an Admob Banner in the layout XML. Use the editor! After adding by the editor, android studio is asking for adding an SDK. Check yes!

  • You need internet access permissions in the App, so add the line:

<uses-permission android:name="android.permission.INTERNET" />" into the manifest file before “<application

  • Now you can change in the XML layout and position of the banner (after you have added a banner with the editor!). For a banner at the bottom over the whole screen, use following code:

<com.google.android.gms.ads.AdView

android:id="@+id/adViewmain"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:visibility="visible"

ads:adSize="SMART_BANNER"

ads:adUnitId="@string/bannerid"

app:layout_constraintBottom_toBottomOf="parent" />

  • I recommend adding a string into strings.xml which is called bannerid. You can do it by adding the following line in the strings.xml:

<string name="bannerid">ca-app-pub-9336898352641187/2817469950</string>

  • Finally you have to implement the banner in the Java. Import following classes:

[if !supportLists]import com.google.android.gms.ads.AdRequest;

[if !supportLists]import com.google.android.gms.ads.AdView;

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

  • In the oncreate method you have to implement:

[if !supportLists]MobileAds.initialize(getApplicationContext(), getString(R.string.bannerid));

[if !supportLists][endif] AdView mAdView = (AdView) findViewById(R.id.adViewmain);

[if !supportLists][endif] AdRequest adRequest = new AdRequest.Builder()

[if !supportLists][endif].build();

[if !supportLists]mAdView.loadAd(adRequest);

  • Now you can compile the app and generate first income by clicking on the banner :-D


 
 
 

Commentaires


Empfohlene Einträge
Versuche es später erneut.
Sobald neue Beiträge veröffentlicht wurden, erscheinen diese hier.
Aktuelle Einträge
Archiv
Schlagwörter
Folgen Sie uns!
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page