Reputation: 2496
I have added AdMob using Firebase.It is not displaying live ads, test ad is working fine. If I add .addTestDevice("D9XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");"
it is showing Test Ad.
I am following steps from Google Documentation.
Project Level - build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
App Level - build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.firebase:firebase-ads:9.0.1'
}
MainActivity.java
AdView mAdView;
AdRequest adRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(getApplicationContext(), "ca-app-pub-XXXXXXXXXXXXXXXX~XXXXXXXXX");
mAdView = (AdView) findViewById(R.id.adView);
adRequest = new AdRequest.Builder().build();
}
activity_main.xml
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_id" />
strings.xml
<string name="banner_id">ca-app-pub-XXXXXXXXXXXX/XXXXXXXXX</string>
I am getting error in Logcat as
W/Ads: There was a problem getting an ad response. ErrorCode: 0
W/Ads: Failed to load ad: 0
I also tried exporting the app for testing live ads, but failed. There are many answer that are telling that, Google might not have ads for my app, but there is no any log showing related to that.
Upvotes: 1
Views: 2675
Reputation: 1
ADD PAYMENT INFO FROM ADMOB ACCOUNT AND WAIT FOR APPROVAL
if the test ads are working fine then your implementation is correct, but there is an option of "Payment" in the admob account which you need to fill. After filling up that form you will receive an email regarding the confirmation of payment details and message indicating that whether your information was accepted by the admob team or not if yes then your live ads will be showing up. but keep in mind that for the first few time the ad won't show up. it takes time to appear after the approval as well. here is the code snippet for the error code to find what is going wrong
mAdView = (com.google.android.gms.ads.AdView) findViewById(R.id.adView);
mAdView.setAdListener(new com.google.android.gms.ads.AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
Toast.makeText(HomeActivity.this, "onAdLoaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdFailedToLoad(int errorCode) {
if(errorCode==AdRequest.ERROR_CODE_INTERNAL_ERROR)
Toast.makeText(HomeActivity.this, "onAdFailedToLoad", Toast.LENGTH_SHORT).show();
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
Toast.makeText(HomeActivity.this, "onAdOpened", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdLeftApplication() {
Toast.makeText(HomeActivity.this, "onAdLeftApplication", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdClosed() {
Toast.makeText(HomeActivity.this, "onAdClosed", Toast.LENGTH_SHORT).show();
}
})
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
get the error code
ERROR_CODE_INTERNAL_ERROR - Something happened internally; for instance, an invalid response was received from the ad server. ERROR_CODE_INVALID_REQUEST - The ad request was invalid; for instance, the ad unit ID was incorrect. ERROR_CODE_NETWORK_ERROR - The ad request was unsuccessful due to network connectivity. ERROR_CODE_NO_FILL - The ad request was successful, but no ad was .
if you are getting error code 3 then after sometime you will get the ads showing up after some time.
Upvotes: 0
Reputation: 379
Look at your string.xml in values folder. If your banner id is not like this
<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
(this id ca-app-pub-3940256099942544/6300978111 is for test ad only)
then replace it with your own banner ad unit id.
Upvotes: -1
Reputation: 25320
You need add mAdView.loadAd(adRequest);
in your code.
You code will look like below:
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);//Required this line to load ad
See Load the ad in the MainActivity class
Upvotes: 0
Reputation: 2693
Make following changes in your code
Add apply plugin: 'com.google.gms.google-services'
at the end of app level build.gradle
.
App Level - build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
apply plugin: 'com.google.gms.google-services'
make load AdRequest
into AdView
by adding mAdView.loadAd(adRequest);
after initializing ad AdRequest
as below :
MainActivity.java
AdView mAdView;
AdRequest adRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(getApplicationContext(), "ca-app-pub-XXXXXXXXXXXXXXXX~XXXXXXXXX");
mAdView = (AdView) findViewById(R.id.adView);
adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
Upvotes: 0