I don't know what I am missing, currently I have:
build gradle(project): maven {
url "https://maven.google.com"
}
build gradle(app):implementation 'com.google.android.gms:play-services-ads:15.0.1'
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
in the xml:
<com.google.android.gms.ads.AdView
android:id="#+id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintEnd_toEndOf="#+id/normBtnID"
app:layout_constraintStart_toStartOf="#+id/ratingBtnID"
app:layout_constraintTop_toBottomOf="#+id/ratingBtnID" />
I have tried several codes, tried to put the adview programmatically and in the xml, for the current code I got the error adSize missing but it's there, when I add the ad programmatically it just shows a blank screen when launches the app
You need to add the following to either the activity or the Application class...
MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
Read more here:
https://developers.google.com/admob/android/quick-start
I thin you must to use firebase firstly you can follow this link to do that and adding ads
in correct way
https://firebase.google.com/docs/admob/android/quick-start
if you did that before
I think the error is from your admob account
go to Payments and confirm info there
ads will appear simply
I hope that will be help you
Could you try android:layout_width="match_parent" and android:layout_height="70dp" on Adview?
I faced same problem yesterday, hardcoded layout_height is work on my case.
Related
I use AdViews in my app in almost every activity.
The xml im using is:
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerInParent="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/Banner_Ads"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintTop_toTopOf="parent"
app:gnt_template_type="#layout/gnt_small_template_view" />
I did every thing I could to test it by either using Test ID for the ads or by setting TestDeviceID and everything works good.
How can I be sure that it will work with real ads? when i did a single check of my app before distribution it gives me ad failed to load : 3.
Yes, I read that it can happen if I created ad unit recently and that it might might take time or that it means that my code is correct but there are no ads. But what does it means no ads? isnt AdView meant to be for ads?
Thank you
What is the appropriate value for adSize in the xml file if I want to include an InterstitialAd and not a Banner?
My problem is that including an InterstitialAd from Admin to my application does not work properly.
So far I followed the official tutorial, but it says nothing about the value of ads:adSize in the xml. When I implemented a ad with a banner this attribute was set with "BANNER" but I suppose this is not the solution when I want to have an Interstitial ad.
So could you please tell me which other values than BANNER are possible for ads:adSize or what else I should use to make it work?
Thanks a lot
Below code required only when you want to add banner view at your App view.
<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-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
Follow instruction of this link to implement InterstitialAd in your App.
I am trying to add my first advertisement to my android app. I followed a tutorial, and added the following code to my xml file
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"
>
</com.google.android.gms.ads.AdView>
It displays the ad in my emulator as well as in my real device . In my emulator, the ads like 'Install This App' are displaying and download symbol also visible. In my emulator , the ad is visible and refreshing clearly but click is not at all enabled. No response with a click.
I googled stack overflow questions but no apt answers were there. Any help will be appreciated.
ps: I didnt try clicking in my emulator due to the admob ban issues
Check Your Layout Arrangements. May be Some other Layouts overlaps the ad container.So when you click it clicks the overlapped layout components.
Make sure the ad is active/ enabled in your admob account. As I remember it shows colour green when active.
Try creating another ad unit and add the ad again.
#arunprakashpj, Your AdView seems ok, but you need to check the parent layout to see if everything is ok.
You need to be sure this isn`t problem of the Ad itself. To prevent the admob ban issues you can set the emulator (or any device) as a Test Device, so you'll get Test banners that you may click without fear.
To see how to implement test banners, check this link (they have an example there): https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start#enjoy_a_freshly_loaded_ad
Please, let us know the click result when you're using the test banners. (If click works in test ads, it means that the problem probably will be the Ad itself and not your code).
The way I solved such problem:
In Unity3D 4.XX in your current Assets folder open
Plugins > Android > AndroidManifest.xml
In the AndroidManifest.xml file under the
application > activity
you can find unityplayer.ForwardNativeEventsToDalvik property, which by default is false, like this:
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
so change it to true,
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
afterthat Save it and re-build.
In my case I was missing adding the ad-mob dependencies to the gradile, once done it worked fine.
I have made an application for the Android Market and I tried to include an Ad in it using Admob. I have everything set up correctly, but the ad doesn't show up no matter what I do. If I check the Admob Marketplace I can see that there were a lot of requests sent and I got a good fillrate, too, but my ads simply do not show up in my program, as if they were invisible.
The AdView appears if I am in the graphical XML designer, but just won't show up when I run the program, although as I said, it sends a request. I would really appreciate it if you could help me out! :)
By the way, here is the main code of the AdView(I tried to add it using Java too, but it didn't show up either):
<com.google.ads.AdView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ad"
ads:loadAdOnCreate="true"
ads:adSize="BANNER"
ads:adUnitId="MyIdHere">
</com.google.ads.AdView>
I found out that the padding of my layout prevented the Adview from
appearing. Removing the padding fixes the problem!
-- answer by Calin
I just started looking into putting Admob ads into the android app I'm building. So far, no good. I've been following the example in the AdMod_Android_SDK_Instructions.pdf that I downloaded from the adMob website, but am confused. On page 7 I see the import statements refer to the package as com.admob.android.ads - but in the SDK I downloaded, the package is com.google.ads - is this a leftover from before google acquired admob? It then goes on to call the method adView.requestFreshAd(); - which does not exist in the latest code.
Please can someone help me out with some code that actually works? My specific errors from logcat are:
AdView missing required XML attribute adUnitId.
... then after I call adView.loadAd(new AdRequest()); i get:
Invalid unknown request error: Cannot determine request type. Is your ad unit Id correct?
onFailedToReceiveAd(Invalid Google Ad request).
Any help, much appreciated!
Thanks.
As of 4.1.0,
mob1lejunkie is perfectly right, you can remove
attrs.xml
background, primarytextcolor, secondarytextcolor attributes (and define them from admob web site on the manage setting tab of your app)
remove the name space xmlns:myapp from your main layout in your xml file and replace it by xmlns:ads (take care here !! The new xmlns is not in /apk/res but apk/lib )
change the namespace of adUnitID and adSize in the adView xml snippet
so here is a working xml snippet with admob 4.1.0 :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="fill_parent"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">
<com.google.ads.AdView android:id="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14d7f7d2180609"
ads:adSize="BANNER" />
</RelativeLayout>
Isn't it a bit light from google to ask devs to put in place a new code and use a librairy that is not yet documented by google themselves ? It reminds me of the adwhirl adventure...
Nevertheless, I must say I am glad google put that in place and remove the attrs.xml stuff. It is much easier to use admob with project inheritance in android.
Also, with respect to using multiple adviews in a project, please note that with this release, it is now possible to add you admob id in the strings.xml file of your application as requested on this thread : http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/c57917b4491a0c1
Just put it this way in your xml layouts for all your adviews :
ads:adUnitId="#string/admob_unit_id"
and then
<string name="admob_unit_id">a14d7f7d2180609</string>
in your strings.xml file and all other localized versions of this file.
This will give you a single centralized location to enter your admob id in all your views.
Great release indeed.
Regards,
Steff
I had the similar issue with 4.1.0 and it turns out Admob documentation (as of 15th May) is out of date.
attrs.xml is no longer needed and the namespace in the layout needs to be
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads
rater then the old
xmlns:ads="http://schemas.android.com/apk/res/com.your.packagename
Seems like the PDF is outdated.
Try reading Google AdMob Ads Android Fundamentals
This page helped me with with placing an ad in the XML layout: http://code.google.com/mobile/ads/docs/android/banner_xml.html