Reputation:
I just want to display Rewarded Video Ad by using test id but it failed again and again while loading.Someone can tell me that what I am doing wrong. Here is my Main Activity Kotlin.
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
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
class MainActivity : AppCompatActivity (), RewardedVideoAdListener {
override fun onRewardedVideoAdClosed() {
loadRewardedVideoAd()
}
override fun onRewardedVideoAdLeftApplication() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onRewardedVideoAdLoaded() {
mRewardedVideoAd.show()
}
override fun onRewardedVideoAdOpened() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onRewardedVideoCompleted() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onRewarded(p0: RewardItem?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onRewardedVideoStarted() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onRewardedVideoAdFailedToLoad(p0: Int) {
Toast.makeText(this,"Failed!",Toast.LENGTH_LONG).show()
}
private lateinit var mRewardedVideoAd: RewardedVideoAd
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713")
// Use an activity context to get the rewarded video instance.
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this)
mRewardedVideoAd.rewardedVideoAdListener = this
loadRewardedVideoAd()
}
private fun loadRewardedVideoAd() {
mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
AdRequest.Builder().build())
}
}
Here is the code that I write in android manifest.
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
Permissions.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Here is the line that I write in build.gradle(project: app_name).
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Here is the line that I write in build.gradle(Module: app).
implementation 'com.google.android.gms:play-services-ads:15.0.1'
Upvotes: 2
Views: 8308
Reputation: 632
Try to put your own app id here, not the one from the tutorial
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713")
You can find your app id in the AdMob account that you created
Upvotes: 0
Reputation: 277
Here are some common causes and how to fix them:
Give it 24 hours, it can take time for an ad to become active in your region Also keep in mind:
It’s too early for the ads to fill. English speaking regions tend to get a faster fill-rate as there are more advertisers targeting these markets. The smaller the market, the slower the fill-rate. Wait 48 hours and see if the issue resolves.
Your region has a slower fill-rate. You notice you’re making income, but when you test the game yourself you can’t see any ads in your game. The region you are testing from may have a slower fill-rate, but advertising is active in the other regions you released for. Wait 48 hours and your region should be updated with active ads.
You haven’t entered your payment details. We have received reports from users, particularly using AdMob, that their banners haven’t filled with active ads until they have entered their payment details into the AdMob account. Update your AdMob account with your payment details and see if the issue resolves in 24 hours.
You’ve waited a few days, and have done all the above but the issue hasn’t resolved. Contact us, we are here to help.
Upvotes: 2