Blogger Text

My Aim to Provide you quality contents, Tips & Tricks, Software, Microsoft Office, Graphic Editing (Adobe PhotoShop, After Affects, Illustrator, inDesign) Corel Draw, Corel Video Studio, Cyberlink PowerDirector, Power ActionCinema, Tutorials about Blogging and VU Assignments, Quizes & GDB Solutions and Much More... at regular Basis
                                     ***    Kindly Subscribe our Official YouTube Channel "INFOPALACESS OFFICIAL-Tuts: in this channel we upload Programming (C,C++,C# JAVA, PHP), Web Development, Graphics Editing and Microsoft Office Step by Step Tutorials from bigginer to Advance Level. We also provide free online courses at our YouTube Channel. ***   Graded Assignments/Quizes and GDB will start in Next Week. Solution ideas of All assignments, Quizes and GDB will be available here. If you have any problem regarding this then you can contact us.

Implement Rewarded Video Ads to Earn Money

Implement Rewarded Video Ads

Developing Applciations for iOS or Android OS is a good technique to engage users or fullfil their requirements but earning revenue from apps is a fruitful for developers. Developers can earn money by monitizing Apps. To monetize the android or iOS apps, Google provided a mobile ad network called AdMob to show the ads in applications. AdMob platform is the perfect solution to easily integrate the ads in our android apps.

Types of Ads

AdMob network provides a different types of ad formats, so we can choose the ads which best fits to our app’s user experience. Following are the different types of ad formats available for android apps.

  • Native Ads
  • Banner Ads
  • Interstitial Ads
  • Rewarded Video Ads

Here I am going to Cover Rewarded Video Ads Implmentation. with out getting more time i just go to the method.

Rewarded Video Ads are the full screen video ads that users have the option of watching in full in exchange for in-app rewards (like get points to use for someting special or unlock premium features etc.). To earn the revenue by integrating Google AdMob ads in android applications, we need to follow below steps.

  • First we need to register an account in AdMob
  • Create ad units in AdMob
  • Interstitial Ads
  • Integrate Google Mobile Ads SDK into an app,

To Implement Rewarded video Ads we need to add following code for google play services to our application build.gradle, for that open your app > Gradle Scripts > build.gradle (Module: app) and add following google play services compile statement to the dependencies{} section.

dependencies {
...
compile 'com.google.android.gms:play-services-ads:11.8.0'
...
}

Now go to res > layouts folder and select the activity where you want to show rewarded video ads in my case I will select MainActivity.xml and add add button which play the video ads, example code for xml activity as shown below.

<!--xml version="1.0" encoding="utf-8"?--> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_height="match_parent" android:layout_width="match_parent" tools:context="com.tutlane.admobexample.MainActivity"> <TextView android:text="Welcome to Infopalacess.com" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="130dp" android:layout_marginTop="150dp"/> <Button android:text="play" android:id="+@id/plyvideo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="130dp" android:layout_marginTop="150dp"/> </RelativeLayout>

Now open your main activity file MainActivity.java from \java\com.infopalacess.rewardedvideoexample path and write the code like as shown below;

MainActivity.java

package com.infopalacess.rewardedvideoexample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.reward.RewardedVideoAd; public class MainActivity extends AppCompatActivity { private RewardedVideoAd rewardedVideoAd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MobileAds.initialize(this, "ca-app-pub-4761500786576152~8215465788"); rewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this); rewardedVideoAd.setRewardedVideoAdListener(this); loadRewardedVideoAd(); } private void loadRewardedVideoAd(){ AdRequest request = new AdRequest.Builder().build(); rewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917", request); Button buttonplay = (Button)findViewById(R.id.plyvideo); // Register the onClick listener with the implementation above buttonplay.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (rewardedVideoAd.isLoaded()) { rewardedVideoAd.show(); } } }); } }

in above code i have used Admob Test Ad Unit and Application Id you have to remove ca-app-pub-4761500786576152~8215465788 with your own application id which can be found in admob account by click left side menu then setting. and also replace this test Ad Unit ca-app-pub-3940256099942544/5224354917 with your own real Admob Ad Unit which is created in Admob account. If you observe above code, we used loadAd() method of RewardedVideoAd class to load an ad with AdRequest input parameter. Here AdRequest parameter is required to hold the runtime information about a single ad request.

You can also add events to this code to get some more functional things place below code outside the OnCreate() method.

@Override public void onRewarded(RewardItem reward) { //Replace it with your own code Toast.makeText(this, "onRewarded! currency: " + reward.getType() + " amount: " + reward.getAmount(), Toast.LENGTH_SHORT).show(); // Reward the user. } @Override public void onRewardedVideoAdLeftApplication() { //Replace it with your own code Toast.makeText(this, "onRewardedVideoAdLeftApplication", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoAdClosed() { //Replace it with your own code Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoAdFailedToLoad(int errorCode) { //Replace it with your own code Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoAdLoaded() { //Replace it with your own code Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoAdOpened() { //Replace it with your own code Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoStarted() { //Replace it with your own code Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoCompleted() { //Replace it with your own code Toast.makeText(this, "onRewardedVideoCompleted", Toast.LENGTH_SHORT).show(); }

When we run above example in android emulator, the Rewarded Video Ads will be displayed on the interface of our app. This is how we can integrate Google AdMob Rewarded Video ads in our android applications to generate the revenue based on our requirements.

Post a Comment

0 Comments