MainActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
MobileAds.initialize(this) {}
MobileAds.setRequestConfiguration(
RequestConfiguration.Builder()
.setTestDeviceIds(listOf("ABCDEF012345"))
.build()
)
val adRequest = AdRequest.Builder().build()
Log.d("Activity", "Is Test Device? : ${adRequest.isTestDevice(this)}")
adView.loadAd(adRequest)
adView.adListener = object : AdListener() {
override fun onAdLoaded() {
super.onAdLoaded()
Log.d("Activity", "@@ onAdLoaded()")
}
override fun onAdFailedToLoad(err: LoadAdError?) {
super.onAdFailedToLoad(err)
Log.d("Activity", "@@ onAdFailedToLoad()\n$err")
}
override fun onAdOpened() {
super.onAdOpened()
Log.d("Activity", "@@ onAdOpened()")
}
override fun onAdClicked() {
super.onAdClicked()
Log.d("Activity", "@@ onAdClicked()")
}
override fun onAdLeftApplication() {
super.onAdLeftApplication()
Log.d("Activity", "@@ onAdLeftApplication()")
}
override fun onAdClosed() {
super.onAdClosed()
Log.d("Activity", "@@ onAdClosed()")
}
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id_for_test" />
</LinearLayout>
string.xml
<resources>
<string name="admob_app_id">ca-app-pub-000000000000~00000000000</string>
<string name="bannera_ad_unit_id_for_test">ca-app-pub-3940256099942544/6300978111</string>
</resources>
I created <meta-dat>
in the manifest and added admob_app_id
as the android:value
value inside. In the AVD test device provided by Android Studio, a test advertisement appeared without any problems, but the test advertisement did not appear on the actual device. So, as in the MainActivity
code above, I called RequestConfiguration
and added my mobile device ID("ABCDEF012345"
) to the test device ID, but the problem was not resolved. The contents of the error were as follows.
I've got a similar issue on Android when using native ads. The error information is very similar :
But, I've got a clue that might be the reason for this: As I've noticed weird crashes sometimes on the app, I've decided to add a check that indeed the app seems valid, by checking its signature.
What I've found is that in this case, at least 2 devices had the app changed (maybe by the same person). So this user for some reason tried to change the app. No idea what he tried to do with it, but I hope this could solve your problem.
If you want, here's a basic way to do it:
Another possible reason :
The time setting is wrong on the device.