I am a new Android Studio developer. I have made 2 apps with AdMob before, but now I made new app with ads, but they not going through. I have also tried with blank app, but the problem persists.
Here is the code below:
First this in MainActivity, the color is red and cannot resolve appear.
When I generate app, this occurred:
I have checked my code 5 times.
Please help me to resolve this.
This is in activity_main:
<com.google.android.gms.ads.AdView
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="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
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
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.
I have quiz app, and I want to make another quiz app that will be about something else.
I created new project in Android Studio and I copied all code from first quiz app.
Everything works fine, only when I start activity that have AdMob ads, app stops working.
In first quiz app everything works fine, ads are shown normally, but new quiz app stops working when trying to load AdMob ads.
Do you know where could be a problem?
This is what I use in xml file for AdMob ads:
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="id"
ads:adSize="SMART_BANNER"
ads:loadAdOnCreate="true"/>
Check the admob documentation and make sure you have the correct app ID set up in the admob details within your Android.manifest
You may have the ID from the previous app in there which will not work as the package name will be different.
https://developers.google.com/mobile-ads-sdk/
You can try
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:background="#drawable/back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="go"
android:orientation="vertical"
tools:context=".MainActivity" >
<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="ca-app-pub-7897489627187383/885626" />
</RelativeLayout>
i have created a game(surfaceview) and i am trying to implement admob wherein it must be fixed at the bottom.. i have successfully implemented the admob and shows it properly but what i did is i call it in main activity.
AdView adView = (AdView)findViewById(R.id.adView);
adView.loadAd(new AdRequest());
and i have this on all layouts
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/unit_id"
ads:loadAdOnCreate="true"
/>
what i need to do is show the admob but it will not be affected even if the screen switches it is fixed in the bottom part of the screen. i have searched for some thing like this but i have no success. i hope someone can help or even explain on how i can achieve this.
P.S. its like 1 banner for all activities.
I think it will be difficult (or impossible) to have just a single unique banner span multiple Activities. The ActivityGroup group class may have allowed this kind of thing, but it was never popular and anyway has been deprecated for a while.
Meantime there remains plenty of demand for the UX motif of switching between major views within the confines of one screen. But the mechanism has been reworked to use Fragments. If you can make your SurfaceView stuff work within a Fragment, then that might be your best bet. A layout might look something like this:
<LinearLayout>
<Fragment>
<AdView>
<LinearLayout>
When I did this kind of thing recently, I just put the AdMob code at the bottom of every Activity, and let it reload a fresh ad with every push. There has been no scolding from the Google side regarding too-frequent ad requests, and I am getting plenty of clicks.
Good luck!
Use Only Xml Coding without Java Code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="App ID"`enter code here`
ads:testDevices="25"
ads:loadAdOnCreate="true" />
</RelativeLayout>
Can you wrap the whole screen in a relative layout? You can then align the banner to the parent's bottom. You other items should be declared with layout_above to keep them above the banner. The easiest way is to wrap them in another layout.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/adView" >
... your other items can go here
</RelativeLayout>
<com.google.ads.AdView
android:id="#id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="App ID"`enter code here`
ads:testDevices="25"
ads:loadAdOnCreate="true" />
</RelativeLayout>
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