-
Monetize your Application by adding Ad banners in your android application
over 10 years ago
-
over 10 years ago
very helpful.
-
over 10 years ago
Adding ad banners into you app
To monetize your app you can add advertisements and earn revenues based on viewers visiting the ads. You'll see below how easily you can add advertisement banners through Admob.
Admobs is a Google acquired company and is one of the largest advertisement platforms with over 40 billion advertisement banners. It offers monetizing and promotion of your app. Admobs support many mobile platforms like android, IOS, webOS, Flash Lite, Windows Phone and all standard mobile browsers.
This is the best practices to show your ads.
follow the steps given below-
In your Android studio project :
- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:21.0.0'
- compile 'com.google.android.gms:play-services:6.+'
- }
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.0' compile 'com.google.android.gms:play-services:6.+' }
Add these lines into your manifest file
- <activity android:name="com.google.android.gms.ads.AdActivity"
android:configchanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode| screenSize|smallestScreenSize"- android:theme="@android:style/Theme.Translucent" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configchanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode| screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
- <relativelayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">- <com.google.android.gms.ads.AdView
- android:id="@+id/adView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- ads:adSize="BANNER"
- ads:adUnitId="@string/banner_ad_unit_id"
- </com.google.android.gms.ads.AdView>
- </relativelayout>
<relativelayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" </com.google.android.gms.ads.AdView>
</relativelayout>
Add this into your string.xml file :
This a default ad unit id for testing purposes.If you already have the advertisement id,you can replace with that. This ID enables you to organise and monitor ads which are displayed to users.
- public static class AdFragment extends Fragment {
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.fragment_ad, container, false);
- }
- @Override
- public void onActivityCreated(Bundle bundle) {
- super.onActivityCreated(bundle);
- AdView mAdView = (AdView) getView().findViewById(R.id.adView);
- AdRequest adRequest = new AdRequest.Builder().build();
- mAdView.loadAd(adRequest);
- }
- }
public static class AdFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_ad, container, false); } @Override public void onActivityCreated(Bundle bundle) { super.onActivityCreated(bundle); AdView mAdView = (AdView) getView().findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); } }
- <fragment
android:id="@+id/adFragment"
android:name="add.the.path.to.AdFragment.class"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<fragment
android:id="@+id/adFragment"
android:name="add.the.path.to.AdFragment.class"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Now,you've given a default ad unit id and the revenue can not be generated . You've to create account in the AdMob website and generate a advertisement id in order to monetize your app.
Generating Advertisement id
over 10 years ago
very helpful.
1 Comment(s)