Google AdMob ads don't show up on the Unity game - android

I did everything on Google's official AdMob tutorial. Test ad was showing up on the editor but when i try it on my phone there are no ads. Google approved my account and still nothing shows up. What do i have to do now?
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using UnityEngine.SceneManagement;
public class AdManager : MonoBehaviour
{
BannerView _banner;
string bannerId = "banner-id";
void Start()
{
MobileAds.Initialize(initStatus => { });
RequestBanner();
}
void RequestBanner()
{
_banner = new BannerView(bannerId, AdSize.Banner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder().Build();
_banner.LoadAd(request);
}
}

Put banner test ID in string bannerId and in your Start() function call this function _banner.Show() after RequestBanner(); function. It will defiantly work.

Related

How to implement Native Ads without MediaView

I want to implement Native Ads in RecyclerView without MediaView, So referred to this tutorial after following this I successfully implemented native ads in RecyclerView but my need is to load only icon, heading, advertiser and call to action button not the MediaView, etc.
So I removed the MediView and other elements Code from the implementation which I made after which the code looks like this
UnifiedNativeAdViewHolder.java
package com.mishracodes.myapplication;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.ads.formats.UnifiedNativeAdView;
public class UnifiedNativeAdViewHolder extends RecyclerView.ViewHolder {
private UnifiedNativeAdView adView;
public UnifiedNativeAdView getAdView() {
return adView;
}
UnifiedNativeAdViewHolder(View view) {
super(view);
adView = view.findViewById(R.id.ad_view);
adView.setHeadlineView(adView.findViewById(R.id.ad_headline));
adView.setCallToActionView(adView.findViewById(R.id.ad_call_to_action));
adView.setIconView(adView.findViewById(R.id.ad_icon));
adView.setAdvertiserView(adView.findViewById(R.id.ad_advertiser));
}
}
and inside the RecyclerViewAdapter.java the part of code which manages NativeAdView
private void populateNativeAdView(UnifiedNativeAd nativeAd,
UnifiedNativeAdView adView) {
((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());
((Button) adView.getCallToActionView()).setText(nativeAd.getCallToAction());
NativeAd.Image icon = nativeAd.getIcon();
if (icon == null) {
adView.getIconView().setVisibility(View.INVISIBLE);
} else {
((ImageView) adView.getIconView()).setImageDrawable(icon.getDrawable());
adView.getIconView().setVisibility(View.VISIBLE);
}
if (nativeAd.getAdvertiser() == null) {
adView.getAdvertiserView().setVisibility(View.INVISIBLE);
} else {
((TextView) adView.getAdvertiserView()).setText(nativeAd.getAdvertiser());
adView.getAdvertiserView().setVisibility(View.VISIBLE);
}
adView.setNativeAd(nativeAd);
}
loading Native Ad function in MainActivity.java
private void loadNativeAds() {
AdLoader.Builder builder = new AdLoader.Builder(this, getString(R.string.ad_unit_id));
adLoader = builder.forUnifiedNativeAd(
new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
#Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
mNativeAds.add(unifiedNativeAd);
if (!adLoader.isLoading()) {
insertAdsInMenuItems();
}
}
}).withAdListener(
new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) {
Log.d("MainActivity", "The previous native ad failed to load. Attempting to"
+ " load another.");
if (!adLoader.isLoading()) {
insertAdsInMenuItems();
}
}
}).build();
adLoader.loadAds(new AdRequest.Builder().build(), NUMBER_OF_ADS);
}
Now after doing this I used Native Ad Validator to validate if the ads are implemented correctly
Result:
But After testing it for sometime I got this error
Warning in detail
So Is there any way to Call for Loading Native Ad so that only those ads are called which do not have Media View. As I have Seen Many Apps which uses native ads like this without Media View.
We can but it was possible before as Google made it mandatory to add MediaView. Also it's a good idea as your revenue would be increased but it may affect the user experience. Finally, you can't do this because if you upload it to the play store then Google will send you a warning notice saying that you didn't add MediaView. It may affect your earnings.
I'm too late, but it helps someone. I found a way to implement native ads without that MediaView.
The logic is Google has provided some native templates. These are for beginners who want to get started with native ads without implementing them from scratch. There are two templates - gnt_small_template_view and gnt_medium_template_view. gnt_small_template_view doesn't have MediaView. You can happily implement it in recycler view and also you can change the layout as per your requirement (but don't change the view ids). The original layout doesn't look good. You mostly change it.
Here is the documentation.
I have added these templates to my app, I didn't face any issue.

Google ads not showing on my game

Well i have my google banner ad script and google mobile ads plugin but for some reason ads are not shown in app after i publish it
When using test ID they work when im testing them
using GoogleMobileAds.Api;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AdScript : MonoBehaviour {
// Use this for initialization
void Start () {
showBannerAd();
}
private void showBannerAd()
{
string adID = "ca-app-pub-4076551740851810/4176317920";
//ca-app-pub-3940256099942544/6300978111 FOR TESTING
//***For Testing in the Device***
//AdRequest request = new AdRequest.Builder()
// Simulator.
//.AddTestDevice("1e84e34350774f47") // My test device.
//.Build();
//***For Production When Submit App***
AdRequest request = new AdRequest.Builder().Build();
BannerView bannerAd = new BannerView(adID, AdSize.SmartBanner, AdPosition.Bottom);
bannerAd.LoadAd(request);
}
// Update is called once per frame
void Update () {
}
}
I have registered them on admob and linked it to my google acc i belive i will provide screen shots and eny additional information if needed
Does your layout have the correct setup by including the below code?
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-4076551740851810/4176317920">
</com.google.android.gms.ads.AdView>

Unity RewardedVideoAds not working

Hello I am trying to implement Admob with unity, I have successfully integrated banner ads and Interstitial ads using the Test ids provided by Admob over here https://developers.google.com/admob/android/test-ads. How ever I am unable to display any rewarded Video ads. When ever I call the RewardedVidosAds nothing shows up and a debug log error displays Ad not ready. This is the following code I am using:
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class AdManager: MonoBehaviour {
public RewardBasedVideoAd rewardBasedVideoAd;
private InterstitialAd fullAdmob;
private bool rewardBasedEventHandlersSet = false;
// reward initialized
public int scoreAmount = 100;
// Use this for initialization
void Start() {
//loading both rewarded and interstitial ads in start.
LoadRewardBasedAd();
//RequestFull ();
}
// Update is called once per frame
void Update() {
}
public void LoadRewardBasedAd() {
rewardBasedVideoAd = RewardBasedVideoAd.Instance;
//Test
AdRequest adRequest = new AdRequest.Builder()
.Build();
rewardBasedVideoAd.LoadAd(adRequest, "ca-app-pub-3940256099942544/5224354917");
}
public void ShowRewardBasedAd() {
if (rewardBasedVideoAd.IsLoaded()) {
Debug.Log("Showiung video");
rewardBasedVideoAd.Show();
} else Debug.Log("not ready");
}
}
I have not currently mediated my video Ads could this be causing the problem? I read that you dont need to mediate your ads if your using a test AdId. I also get the following errors in my logcat when calling for a rewardedVideoAd
Fail to instantiate adapter com.google.DummyAdapter
Fail to load ad:3

Interstitial Ads not showing admob plugin for unity

I am trying to put an interstitial ad after every 5 games the user plays. What I've done is created an empty object with the following script:
using UnityEngine;
using GoogleMobileAds.Api;
public class AdBetweenGames : MonoBehaviour {
InterstitialAd interstitial;
void Start()
{
if(PlayerPrefs.GetInt("games-played", -1) % 5 == 0)
{
this.ShowInterstitial();
}
}
private void RequestInterstitial()
{
string adUnitId = "UNITID";
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
public void ShowInterstitial()
{
RequestInterstitial();
Debug.Log("Interstatial ad called.");
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
}
I am sure the code here is called properly based on the debug log. I've also tried doing banner ads and they show without a problem after 1-2 seconds. I am making an android game.
Also I was thinking, could it be that the ad needs some extra time to load and I am clicking try again too early. But then what would a solution be?
The interstitial ad of ad mob need time to load try it in update and wait for at least 4 sec and call ShowInterstitial function inside a bool set its value true in start and false it after calling the function to show ad once.

Admob unity rewarded videos not working

I was using Unity ads on my android game and everything was working perfectly, except from some devices where Unity ads where not showing sometimes. So, I wanted to test Admob rewarded video to see if I could get a better performance. Here's the code I'm using for Admob:
public void RequestRewardBasedVideo()
{
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-243186545632812xxxxxxxxxxxx";
#elif UNITY_IPHONE
string adUnitId = "unused";
#else
string adUnitId = "unexpected_platform";
#endif
RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
AdRequest request = new AdRequest.Builder().Build();
rewardBasedVideo.LoadAd(request, adUnitId);
showAdvertisment(rewardBasedVideo);
}
private void showAdvertisment(RewardBasedVideoAd rewardBasedVideo)
{
if (rewardBasedVideo.IsLoaded())
{
rewardBasedVideo.Show();
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
}
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
//reward
}
I assigned the RequestRewardBasedVideo() to a button, but the issue is that the videos are not showing! I think I'm in the right path because when I click the button, the console logs:
Dummy .ctor
Dummy CreateRewardBasedVideoAd
Dummy LoadAd
Dummy IsLoaded
Dummy ShowRewardBasedVideoAd
I have already tried putting the app on my Android device and imported the Google Admob package for Unity, also configured the ads in the Admob panel. Anyone have any ideas for what I can do to solve this??
It may be due to no reward video or no ad video available currently. Try testing with test ads. Do include test device ID in your request code like this:
AdRequest request = new AdRequest.Builder()
.AddTestDevice("34343")
.Build();
Try with sample ad UNIT Id. Hopefully it works.
Your code is wrong. You should separate request ad and show ad into two functions. In Start() function, you call request function and show ad function should be hooked into your button. It's because when you request ad, it'll take some time to make ad available for you.
what if video isn't loaded? You need to handle that case, listen to load event and then hit show.
if (rewardBasedVideo.IsLoaded())
{
rewardBasedVideo.Show();
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
}else{
rewardBasedVideo.OnAdLoaded += HandleVideoLoaded;
}
public void HandleVideoLoaded(object sender, Reward args)
{
rewardBasedVideo.Show();
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
rewardBasedVideo.OnAdRewarded -= HandleRewardBasedVideoRewarded;
}

Categories

Resources