• 3

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I am setting the use of a banner ad for my android app. I've followed the official doc at: https://developers.google.com/admob/android/quick-start

The doubt I want to clearify is that some tutorials over the internet say that you need to add the code bellow in android manifest:

   <uses-permission android:name="android.permission.INTERNET"/>
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

   <meta-data android:name="com.google.android.gms.version"

    <activity android:name="com.google.android.gms.ads.AdActivity"

The official doc doesn't state anything about that, so what then? Will my ads work properly without that?

First you have to add below dependency in your gradle file:

implementation 'com.google.android.gms:play-services-ads:17.1.1'

Then You have to add meta-data tag in your manifest that specifies your admob application id. So add below code to your manifest in application tag:

        android:value="your admob application id"/>

and if you want to test ads in your app, you can use sample application id provided by google itself, which is as below:


Now you can implement all types of ads by your own and first use test ad unit ID for testing purpose. It shows that your ads will be showed or not. Test ad unit Ids are as follows:

For Banner Ad:  ca-app-pub-3940256099942544/6300978111
For Interstitial Ad:  ca-app-pub-3940256099942544/1033173712
For Native Ad:  ca-app-pub-3940256099942544/2247696110
For Rewarded Video Ad:  ca-app-pub-3940256099942544/5224354917
  • 1
Reply Report
      • 1
    • I've done all that, ads are showing in the app, so no need to add permissions or the "com.google.android.gms.ads.AdActivity" tag in the android manifest? that's what I want to know, tutorials over the internet all say to add those pieces of code
      • 2
    • If you initialize MobileAds in your java file using MobileAds.initialize(this, "YOUR_ADMOB_APP_ID"); then you don't have to add meta-data tag in manifest as it is used only for initializing ads
      • 2
    • ok, thank you, I am using MobileAds.initialize(this, "YOUR_ADMOB_APP_ID") and I only added the internet and state permissions, just in case, the other pieces of code I didn't, it is working fine so well, I was just wondering if my ads wouldn't work properly if not added or something, I will accept your answer