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 :
Download google repository in your SDK which is present in the extras section.
Add dependency into Application level build.gradle file (There is a project level and a application level build.gradle file) : com.google.android.gms:play-services:6.+
your dependencies will resemble like this:
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.
Create a fragment:
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);
}
}
Add this fragment wherever you want to show your add in the activity
and in android:name attribute write the path to AdFragment.
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.
Now click on Monetize new App and follow the instructions . They will ask your project or aplication name . And you can customize the advertisement type as per your needs .
Finally, a new ad unit id will be generated .
Replace the value of the string banner_ad_unit_id with that value.
Run the application again. And you can analyse your ad views in your AdMob account.
1 Comment(s)