[STEP BY STEP] Android App AdMobs реклами

View previous topic View next topic Go down

[STEP BY STEP] Android App AdMobs реклами

Post by user45 on Thu Sep 08, 2016 10:54 am

Сайта от който тръгвам е https://www.google.com/admob/

Първото нещо, което трябва да се направи е да се добави в build.graddle в dependcies -  compile 'com.google.firebase:firebase-ads:10.2.0'

Code:
dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            compile 'com.android.support:appcompat-v7:xx.x.x'
            compile 'com.google.firebase:firebase-ads:10.2.0'
        }
apply plugin: 'com.google.gms.google-services'
https://firebase.google.com/docs/admob/android/quick-start wrote:If the two lines in bold above are not already in your app-level build.gradle, add them. Place the compile statement inside the dependencies section and the apply plugin statement at the bottom.

След това в /res/values/string.xml трябва да добавя string_id на banner-a

Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My Application</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
</resources>

// Стоян: аз си мисля да си направя отделен файл както има values/games-ids.xml, нещо като banners-ids.xml

Третата стъпка е Place an AdView in your main activity layout
В parent layout-a се добавя
Code:
xmlns:ads="http://schemas.android.com/apk/res-auto"

и някъде в xml-a

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

Това е placeholder-a на baner-a.

Оттам отиваме в кода на активитито
в onCreate() се добавя

Code:
MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");

https://firebase.google.com/docs/admob/android/quick-start wrote:To find your app ID, click the App management option under the settings dropdown (located in the upper right-hand corner) on the AdMob account page. App IDs have the form ca-app-pub-XXXXXXXXXXXXXXXX~NNNNNNNNNN.

Като import-и трябва да се добавят:
Code:
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

Code:
а след MobileAds.initialise(..)

AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Важно: Когато се тества рекламите се пускат в debug mode и не трябва да се клика отгоре им. Иначе има опасност от suspend-ване на AdMob акаунта.

user45

Posts : 314
Points : 710
Reputation : 0
Join date : 2014-09-11

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum