Admob banner visible in preview mode, but not when running - android

Im trying to add a banner to my Android application, but can't get it to work. The banner is visible in the preview but not when running on my Genymotion device. This is my layout-file:
<LinearLayout 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"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.my.package.MapsActivity"
tools:layout="#android:layout/list_content"
android:orientation="vertical">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="450dip"
tools:context="com.example.my.package.MapsActivity"/>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"/>
</LinearLayout>
And in the Activity-file I have this code:
MobileAds.initialize(mContext, "ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxx");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
It does not work with test ads either. What can be wrong?
Hank

One thing I would like to say that whenever you create a banner or interstitial than you have to wait for few hours for ads to display on your mobile screen.

Maybe your gmail account used in the Genymotion is the same with admob account. Try change to another gmail in your Genymotion.

Related

Android Admob Integration Doesn't show ad

i've sucessfully integrate Admob in my app . i have my Admob key . but it isn't working . it is not showing ads in app.
This is my XML . this is what i've done so far
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.radioaudio.motivationalaudios.MyYouTubePlayer">
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/youtube_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/videoTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Arise, Awake and stop not till the truth is known - Radio Story | IIT Kanpur Radio"
android:textColor="#000"
android:textSize="20dp" />
<com.google.android.gms.ads.NativeExpressAdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-5059726881726792/7013814664"
ads:adSize="280x132">
</com.google.android.gms.ads.NativeExpressAdView>
</LinearLayout>
my java code
NativeExpressAdView adView = (NativeExpressAdView) findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder()
.addTestDevice("A5E3E2068BD88202CBC281AD76984BEE")
.build();
adView.loadAd(request);
Native ads takes time to show. So kindly wait for 2-3 hours. They will pop up automatically. you might created your Account just a minute ago ..

Android Ads with AdMob and Firebase

I'm trying to add a smaller banner image to the bottom of one of the pages in my app. I'm running into a sort of loopy problem:
The code in the XML file is:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/lib/com.sidekickz.myadventure.activity_hero_picture.xml"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
<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_alignParentBottom="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>
I've tried all variations of xmlns:app/android/ads but I either run into the issue of all the "android" tags not being supported, or something else.
MobileAds.initialize(getApplicationContext(), "appnumber");
AdView mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdSize(AdSize.SMART_BANNER);
mAdView.setAdUnitId("appnumberthing");
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
But at BEST my app shows an image saying that the ad size isn't set. If I follow the suggestions online to alter it, doing so results in Adsize and AdUnitId need to be set before loading.
Any help would be awesome and you would deserve a hug.
Thanks

My app was suspended due to an issue with ads

today Google suspended my app saying that my ads violated Google TOS but I don't know what did it actually violate. I think there might be something wrong with my code structure i guess because I tried publishing it two times and in both it got suspended.
In my app I am using a View Pager and inside it I have 4 tabs. So the ads are placed in the View Pager as below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<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"
app:adSize="SMART_BANNER"
app:adUnitId="#string/banner_ad_unit_id" >
</com.google.android.gms.ads.AdView>
and the code in the View Pager activity
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
I would be very thankful if someone told me the reason behind the continuous suspension.

Cannot get AdMobs to display over map

I have followed this tutorial: AdMob Code
But I cannot get the banner to display (not even the common XML adSize error that I have seen a lot of online:
This is the code in my main_activity:
private AdView adView;
private static final String AD_UNIT_ID = "ca-app-pub-XXXXXXXXXXXXXXXXXX";
GoogleMap mMap;
LatLng myposition;
Marker marker;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
//Add the AdView to the view hierarchy.The view will have no size
//Until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.lyout);
layout.addView(adView);
//Create an ad request. Check kogcat output for the hashed device ID to
//get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("MY_DEVICE_ID")
.build();
//Start loading the ad in the background.
adView.loadAd(adRequest);
}
And this is my layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/lyout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.MapFragment"
android:id="#+id/the_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTilt="45"
map:cameraZoom="15"
/>
</LinearLayout>
At first my layout file was only:
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.MapFragment"
android:id="#+id/the_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTilt="45"
map:cameraZoom="15"
/>
EDIT: LogCat removed as working
But that wasn't working either. How do I get these ads to display?
Thanks
You can load the banner ad like below from the xml layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:testDevices="TEST_EMULATOR"
ads:loadAdOnCreate="true"
ads:adSize="BANNER"/>
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.MapFragment"
android:id="#+id/the_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTilt="45"
map:cameraZoom="15" />
</LinearLayout>
Note: if you have generated your appId just recently in admob account then may be there will be no advertise to display for your id to Admob engine so wait for a while and then try again. May be that will also work.
Hope it will help you..

Fixed ad at the bottom of PrefereceActivity

I have a PreferenceActivity for a LiveWallpaper and have used the solution here (LINK) to create an Admob ad. It works, but the ad disappers when the user scrolls up or down and loads again when it comes into view. Is there a way so that the ad always stays at the bottom (or top) of the activity (like in a regular activity)?
Before
((LinearLayout)view).addView(adView);
Try setting the layoutParam like
adView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT))
OR Change the layout like following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="#string/ad_unit_id"/>
</RelativeLayout>
And code part would be like this:
mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdListener(new ToastAdListener(this));
mAdView.loadAd(new AdRequest.Builder().build());

Categories

Resources