I was stuck for 3 days on implementing AdMob Rewarded Video Mediation with Applovin and Chartboost, the code is completely find but when I launch the app it's said "onRewardedVideoAdFailedToLoad" and ad won't display. Below is my code, kindly please help me if I make any mistake in code or not.
import com.applovin.sdk.AppLovinSdk;
import com.chartboost.sdk.Chartboost;
import com.google.ads.mediation.chartboost.ChartboostAdapter;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardItem;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;
public class MainActivity extends Activity implements RewardedVideoAdListener {
private Button rewarded_video;
private RewardedVideoAd mAd;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AppLovinSdk.initializeSdk(getApplicationContext());
AppLovinIncentivizedInterstitial myIncent = AppLovinIncentivizedInterstitial.create(this);
myIncent.preload(null);
Chartboost.startWithAppId(this, "xxxxxx", "xxxxxx");
Chartboost.onCreate(this);
MobileAds.initialize(this, APP_ID);
mAd = MobileAds.getRewardedVideoAdInstance(this);
mAd.setRewardedVideoAdListener(this);
Bundle bundle = new Bundle();
bundle.putBoolean("mute_audio", true);
AdRequest adRequest = new AdRequest.Builder()
.addNetworkExtrasBundle(ChartboostAdapter.class, bundle)
.addNetworkExtrasBundle(ApplovinAdapter.class, bundle)
.build();
mAd.loadAd(AD_UNIT_ID, adRequest);
rewarded_video = (Button) findViewById(R.id.rewarded_interstitial);
rewarded_video.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mAd.isLoaded()) {
mAd.show();
}
}
});
}
@Override
public void onResume() {
mAd.resume(this);
super.onResume();
Chartboost.onResume(this);
}
@Override
public void onPause() {
mAd.pause(this);
super.onPause();
Chartboost.onPause(this);
}
@Override
public void onDestroy() {
mAd.destroy(this);
super.onDestroy();
Chartboost.onDestroy(this);
}
@Override
public void onStop() {
super.onStop();
Chartboost.onStop(this);
}
@Override
public void onBackPressed() {
// If an interstitial is on screen, close it.
if (Chartboost.onBackPressed())
return;
else
super.onBackPressed();
}
@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();
//rewarded_video.setVisibility(View.GONE);
}
@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 onRewarded(RewardItem reward) {
}
@Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}
}
Thank you so much for your kindly help.
Are you trying to mediate AppLoving and Chartboost through AdMob, or are you trying to call the AppLovin and Chartboost SDKs outside of Admob?
It looks like you're trying to initialize both AppLovin and Chartboost SDKs separately, and then trying to use a show call for AdMob itself while those two ad sources are unmediated. The last I checked, AdMob itself doesn't support Rewarded Videos and instead relies on other Ad network sources to display rewarded videos, which is probably why you're not getting anything. Just a sidenote, you've set everything up in AdMob's dashboard already, yes? (As in, setting up the Mediation sources and setting proper ad units)
In order for the code as it is now to work, you're going to want to Chartboost's or AppLovin's own show calls for the ads in order to display a rewarded video, not AdMob's. If you're trying to mediate, AdMob has a guide on their site to help you out. They also have a guide for AppLovin as well as all of their approved integration partners.
Hope this helps.