Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 184.108.40.206 release ready!
Owner and Founder. Opencart
AdMob by Google is an advertising platform designed for mobile app developers. It helps you to monetize your app and start earning from it by displaying ads from Google in their apps. It is the top choice for the developers because it is easy and free to implement, does most of the work by itself and you can start earning without any complex coding. It is fully customizable, you can select where to show ads and what type of ads to be displayed.
To get started with AdMob, you need a Google account which will be used to login to AdMob console. You need to add your app and then create some ad units which you will be using in your app. Creating Ad Units is easy. All you need to do is follow the instructions provided by Google but in this blog, we will be focusing on how to implement them in your Android application.
You can fully control the ads that will be displayed in your application. And for that, you can go to AdMob console and select your app. Then select “Blocking Controls” which will show the list of all the types of ads that can be displayed in your app. You can use the switch provided to disable the ads you don’t want.
Below is the screenshot of the AdMob console where you can block the particular ads.
1) You need to add the ads dependency in your module level build.gradle.
2) You need to initialize Mobile Ads. This can be done in your Application class or you can do this anytime before creating an ad but only once.
3) In case you are using test ads which you should while developing the app. You need to register your device to show test apps. Otherwise, your apps will be not be displayed. Below provided code segment helps you to do this.
If you want to find out your test device id then check the logcat output for a message that looks like this:
Now we are ready to get the ads in our app and start earning. Let us now look at various types of ads provide by Google and how to implement them.
1) Banner Ads: They are rectangular image or text ads that stay on the app layout while the user interacts with the app and refresh automatically. These can be implemented in two ways.
i) Directly in XML means you can add the AdView in your XML and pass the adSize and adUnitId in the attributes and it will automatically load the ad for you.
ii) You can also add the banner type ad programmatically.
In both the cases, you would have to pass the adSize and adUnitId without them the ads will not appear.
Below is the screenshot of the Banner Ads.
2) Interstitial Ads: These are the full page ads which cover the full screen of the app. They are displayed at certain points in the application like between a transition. To implement it, we need to declare an object of the InterstitialAd class.
In the above code segment, we have created an object of the InterstitialAd class and initialized it. We have also added a listener which will show the ad as soon as it gets completely loaded. It is a good practice to load the ad a little earlier to avoid loading delay and just call the show().
Below is the screenshot of the Interstitial Ads.
3) Rewarded Video Ads: Rewarded video ads are full-screen video ads that users have the option of watching in full in exchange for in-app rewards. To implement these type of ads, you need to implement the RewardedVideoAdListener interface and then create an object of RewardedVideoAd class.
this will initialize your video ad and you need to call the show() function to show the ad.
When you implement the RewardedVideoAdListener interface then you will have to override its functions which will be executed according to situations like whether the user have completely watched the ad or not. the overridden methods will look like this.
Below is the video of the Rewarded Video Ads.
You can do whatever you want according to your need.
That’s all for this blog. We have Native Ads Express too but they are deprecated now and Native Ads Advanced is currently in a limited beta release. You can always check googles documentation of AdMob for more information.
Thank you very much. This is Vedesh Kumar signing off.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
ok i run and init the game class from mainactivity….
ok, heres the code that makes the trick, in onCreate in activity that sets up the game, fullscreen surface view , fixed size framebuffer, anyway:
mGame = new Game(this); //this is Context
//Makes an admob banner ad at the bottom of the fullscreen surface, dono what the code does, but it works…:)
WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
windowParams.gravity = Gravity.BOTTOM;
windowParams.x = 0;
windowParams.y = 0;
windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
windowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
windowParams.format = PixelFormat.TRANSLUCENT;
windowParams.windowAnimations = 0;
WindowManager wm = getWindowManager();
// Create the adView
adView = new AdView(this);
adView.setAdUnitId(“ca-app-pub-3940256099942544/6300978111”); //test ad id….
// Initiate a generic request to load it with an ad
.addTestDevice(“2EE27C29EF745B2252F293AAE9539279”) //youre device id….
// Add adView to WindowManager
that does the trick! no xml needed and struggle with tthat shit. 🙂 hate xml ….look different everywhere and shit to code. lol i love fullscreen…and this sets the add att bottom of that fullscreen.
For officially we would recommend that you use these links –>
1) https://rnfirebase.io/docs/v5.x.x/installation/initial-setup –> for the basic idea of integrating the firebase in your react native code.
2) https://rnfirebase.io/docs/v5.x.x/admob/android –> for the integration of admob in your react native code.
But still, in case you want to mix things up in react native and native code then you will have to create a custom view for displaying ads in the runtime from your MainActivity.java file and then attach the same to your screen.
You can see the comment by pazo on how to create a dynamic view without any XML code and then attach the same to your current window.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.