Implement google admob video reward in aide ide
Tutorial on how to implement google admob video rewards to your android project using aid ide in android. Rewarded video ads are full-screen video ads that users have the option of watching in full in exchange for in-app rewards.
Now let start, first in your "build.gradle" add this code:
compile 'com.google.android.gms:play-services-ads:+'
Next goto your "AndroidManifest.xml" and add this following codes:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
Next goto your java files e.g "MainActivity.java" and this following codes:
import com.google.android.gms.ads.*;
import com.google.android.gms.ads.reward.*;
implements RewardedVideoAdListener
private RewardedVideoAd mRewardedVideoAd;
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713"); //video rewarded
// Use an activity context to get the rewarded video instance.
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
mRewardedVideoAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();
private void loadRewardedVideoAd() {
mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
new AdRequest.Builder().build());
}
@Override
public void onRewarded(RewardItem reward) {
Toast.makeText(this, "onRewarded! currency: " + reward.getType() + " amount: " +
reward.getAmount(), Toast.LENGTH_SHORT).show();
// Reward the user.
}
@Override
public void onRewardedVideoAdLeftApplication() {
Toast.makeText(this, "onRewardedVideoAdLeftApplication",
Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdClosed() {
Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdLoaded() {
Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdOpened() {
Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}
And when you want to call the video reward to your activity use this codes.
if (mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.show();
}
Done, for more tutorials regarding to admob implementation i recommend to read this Implement google admob banner ads in aide ide and this Implement google admob interstitial ads in aide ide
For alternative admob you can use startapp ads.
for more information about google admob video rewards please visit this link https://developers.google.com/admob/android/rewarded-video
Comments
Post a Comment
Leave a comment hdh