jle
jle

Reputation: 696

android - AdMob ads without firebase

I want to integrate AdMob ads to my new android project, but I get an error when the app tries to load the ad. There was a problem getting an ad response.ErrorCode: 0 and Failed to load ad: 0. I don't want to integrate firebase

I added the play-services to my gradle file:

dependencies {
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services:10.0.1'
}

This to my manifest.xml:

</application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

This to my activity_main.xml:

xmlns:ads="http://schemas.android.com/apk/res-auto"

and

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_home_footer"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true">
    </com.google.android.gms.ads.AdView>

And in my code I added:

AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Upvotes: 1

Views: 2459

Answers (2)

Hardtack
Hardtack

Reputation: 317

I have AdMob without FireBase. This is working code.

Gradle:

 dependencies {
     compile 'com.google.android.gms:play-services-ads:10.0.1'
}

Manifest:

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

activity_main.xml:

xmlns:ads="http://schemas.android.com/apk/res-auto"

and

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        ads:adSize="SMART_BANNER"               ads:adUnitId="@string/banner_ad_unit_id"
        android:layout_width="wrap_content"     android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"  android:layout_alignParentTop="true"
        android:layout_marginBottom="5dp">
</com.google.android.gms.ads.AdView>

and in my code

AdView mAdView = (AdView) findViewById(R.id.adView);        
MobileAds.initialize(getApplicationContext(), "ca-app-pub-XXXXXXXXXXXXXXXX~XXXXXXXXXX");
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Upvotes: 1

Pztar
Pztar

Reputation: 4779

If you go here: https://developers.google.com/android/guides/setup you'll find all the Google Play services you can use including ads. Add this dependency:

dependencies {
    compile 'com.google.android.gms:play-services-ads:10.0.1'
}

Upvotes: 2

Related Questions