Admob not displaying on Android Platform

3 min


0

I’m having bother displaying advert inside my android app in xamarin type, in iOS every thing appears to work wonderful however on Android I’m simply getting a clean view right here the 2 screenshot :

right here is my android manifest

<?xml model="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="2.0" package deal="it.HangoverApp.Hangover" android:installLocation="auto" android:versionCode="1">
    <uses-sdk android:minSdkVersion="26" android:targetSdkVersion="27" />
    <uses-permission android:title="android.permission.CAMERA" />
    <uses-permission android:title="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:title="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:title="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:title="android.permission.INTERNET" />
    <uses-permission android:title="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:title="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:title="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:title="android.permission.ACCESS_WIFI_STATE" />
    <exercise android:title="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
    <software android:label="Hangover.Android" android:title="android.support.multidex.MultiDexApplication">
        <receiver android:title="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
        <receiver android:title="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <motion android:title="com.google.android.c2dm.intent.RECEIVE" />
                <motion android:title="com.google.android.c2dm.intent.REGISTRATION" />
                <class android:title="${applicationId}" />
            </intent-filter>
        </receiver>
        <supplier android:title="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
            <meta-data android:title="android.support.FILE_PROVIDER_PATHS" android:useful resource="@xml/file_paths"></meta-data>
        </supplier>
        <meta-data android:title="com.google.android.gms.ads.APPLICATION_ID" android:worth="ca-app-pub-3926326346203258~3222437594" />
        <meta-data android:title="com.google.android.maps.v2.API_KEY" android:worth="AIzaSyDhDVDVl6Z1vO9CwAL9xx2ypjMw-QhZAHw" />
        <meta-data android:title="com.google.android.gms.version" android:worth="@integer/google_play_services_version" />
        <supplier android:authorities="com.facebook.app.FacebookContentProvider614171362072741" android:title="com.facebook.FacebookContentProvider" android:exported="true" />
        <meta-data android:title="com.facebook.sdk.ApplicationId" android:worth="@string/facebook_app_id" />
        <exercise android:title="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/facebook_app_name" />
        <exercise android:title="com.facebook.CustomTabActivity" android:exported="true">
            <intent-filter>
                <motion android:title="android.intent.action.VIEW" />
                <class android:title="android.intent.category.DEFAULT" />
                <class android:title="android.intent.category.BROWSABLE" />
                <knowledge android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </exercise>
    </software>
</manifest>

Here is the code of the cell:

xmlns:cs="clr-namespace:Hangover.GUIPersonalizzata;assembly=Hangover" 
      <Frame  HasShadow="True" CornerRadius="15" IsVisible = "{Binding shouldDisplayAd}"
                    HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HeightRequest = "255"
                    Margin="5,3,5,1" BackgroundColor="White" Padding="0" IsClippedToBounds="True">

                    <cs:AdMobView Size="MediumRectangle" VerticalOptions="EndAndExpand"/>  

               </Frame>

Here is the AdMobView:

utilizing System;
utilizing Xamarin.Forms;

namespace Hangover.GUIPersonalizzata
{
    ///Custom renderer per la pubblicità
    public class AdMobView : View
    {
        public enum Sizes { Standardbanner, MassiveBanner, MediumRectangle, FullBanner, Leaderboard, GoodBannerPortrait }
        public Sizes Size { get; set; }

        public AdMobView()
        {
            this.BackgroundColor = Color.Black;
        }
    }
}

And right here the customized renderer:

utilizing Android.Content;
utilizing Android.Gms.Ads;
utilizing Hangover.Droid.CustomRenderer;
utilizing Hangover.GUIPersonalizzata;
utilizing Xamarin.Forms;
utilizing Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobViewRenderer))]
namespace Hangover.Droid.CustomRenderer
{
    public class AdMobViewRenderer : ViewRenderer
    {
        Context context;

        public AdMobViewRenderer(Context _context) : base(_context)
        {
            context = _context;
        }
        protected override void OnElementModified(ElementModifiedEventArgs<View> e)
        {
            base.OnElementModified(e);
            if (e.OutdatedElement == null)
            {
                var advertView = new AdView(Context);
                change ((Element as AdMobView).Size)
                {
                    case AdMobView.Sizes.Standardbanner:
                        advertView.AdSize = AdSize.Banner;
                        break;
                    case AdMobView.Sizes.MassiveBanner:
                        advertView.AdSize = AdSize.MassiveBanner;
                        break;
                    case AdMobView.Sizes.MediumRectangle:
                        advertView.AdSize = AdSize.MediumRectangle;
                        break;
                    case AdMobView.Sizes.FullBanner:
                        advertView.AdSize = AdSize.FullBanner;
                        break;
                    case AdMobView.Sizes.Leaderboard:
                        advertView.AdSize = AdSize.Leaderboard;
                        break;
                    case AdMobView.Sizes.GoodBannerPortrait:
                        advertView.AdSize = AdSize.GoodBanner;
                        break;
                    default:
                        advertView.AdSize = AdSize.Banner;
                        break;
                }

                advertView.AdUnitId = App.getBannerId();
                var requestbuilder = new AdRequest.Builder();
                advertView.LoadAd(requestbuilder.Build());
                SetNativeControl(advertView);
            }
        }

    }
}

Here the ids:

public static String getBannerId()
        {
            if (TESTMODE)
                return "ca-app-pub-3940256099942544/2934735716";
            if (Device.RuntimePlatform == Device.iOS)
                return "ca-app-pub-3926326346203258/2224942897";
            if (Device.RuntimePlatform == Device.Android)
                return "ca-app-pub-3926326346203258/8267251849";
            return "";
        }
        public static String getAppAddId()
        {
            if (Device.RuntimePlatform == Device.iOS)
                return "ca-app-pub-3926326346203258~6439520076";
            if (Device.RuntimePlatform == Device.Android)
                return "ca-app-pub-3926326346203258~3222437594";
            return "";
        }

Here is the log output from the advert:

[Ads] Use AdRequest.Builder.addTestDevice(“23A6FE4B4656BDF0239595258F8C1876”) to get take a look at advertisements on this system.
[DynamitePackage] Instantiating com.google.android.gms.advertisements.ChimeraAdManagerCreatorImpl
[Ads] Use

AdRequest.Builder.addTestDevice("23A6FE4B4656BDF0239595258F8C1876") to get take a look at advertisements on this system.
[Ads] Not retrying to fetch app settings
[Ads] Ad didn't load : 3
[Ads] Ad didn't load : 3

Even if the app is in launch mode, any concepts?


What's Your Reaction?

hate hate
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win

0 Comments

Your email address will not be published. Required fields are marked *

Choose A Format
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Poll
Voting to make decisions or determine opinions
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Meme
Upload your own images to make custom memes
Video
Youtube, Vimeo or Vine Embeds
Audio
Soundcloud or Mixcloud Embeds
Image
Photo or GIF
Gif
GIF format