My doubt is not weather its ok to click on live ads during development.I did all the formalities to get my admob ad working . Then i saw that we should only use test add during development . so i used this code:
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4") // An example device ID
.build();
It worked fine. But then i change i back to the live ad code fearing that i would forget to do so later:
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
But now the ad wont appear during test run. Is that normal?
will the ad work when i finally launch the app?
I dont see anything wrong with your code, but something similar happened to me when implementing admob too.
I didnt have in count that the ad must be loaded before showing it, and that the loading may take some time. If you try to show an ad that its not loaded, a black activity might be shown.
You should implement some waiting time or a listener in order to be sure that the add is loaded before showing it.
public InterstitialAd interstitialAd;
[...]
public void setNewInterstitialRequest()
{
interstitialAd = new InterstitialAd(CurrActivity.this);
interstitialAd.setAdUnitId("ca-app-pub-***************************");
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice("ZY22247DJV")
.build();
// Begin loading your interstitial.
interstitialAd.loadAd(adRequest);
//add listener so you know is fully loaded
interstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
[...] // <- code you want to execute as soon as the ad is loaded
}
});
}
public void displayAd() {
try {
//verify is loaded before showing a black screen
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
//else
// showToast("Not loaded");
}
catch (Exception ex){}
}
So taking this in mind, if you want for the ad to be shown inmediately when something happens, you should have it loaded before that event occurs.
Related
I run my app with android studio, but my add doesn't appear...
Every time I run my app no ads appear and I get this error message in Logcat:
"There was a problem getting an ad response. ErrorCode: 0 Failed to
load ad:0"
Here is my MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(MainActivity.this, "ca-app-pub-4760206671218452~8890405785");
mAdview = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
mAdview.loadAd(adRequest);
mAdview.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
Toast.makeText(getApplicationContext(),"RKAd Loaded",Toast.LENGTH_SHORT).show();
// Code to be executed when an ad finishes loading.
}
#Override
public void onAdFailedToLoad(int errorCode) {
Toast.makeText(getApplicationContext(),"Ad Failed to load",Toast.LENGTH_SHORT).show();
// Code to be executed when an ad request fails.
}
#Override
public void onAdOpened() {
Toast.makeText(getApplicationContext(),"Ad Opened",Toast.LENGTH_SHORT).show();
// Code to be executed when an ad opens an overlay that
// covers the screen.
}
#Override
public void onAdLeftApplication() {
Toast.makeText(getApplicationContext(),"Ad Left Application",Toast.LENGTH_SHORT).show();
// Code to be executed when the user has left the app.
}
#Override
public void onAdClosed() {
Toast.makeText(getApplicationContext(),"RKAd Closed",Toast.LENGTH_SHORT).show();
// Code to be executed when when the user is about to return
// to the app after tapping on an ad.
}
});
Here my activity_main.xml
<com.google.android.gms.ads.AdView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
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="SMART_BANNER"
android:layout_gravity="bottom"
ads:adUnitId="ca-app-pub-4760206671218452/1505195192">
</com.google.android.gms.ads.AdView>
I have on the screen Ad Failed to load. I created my Admob account yesterday, but the ad doesn't display :(
1. If your account is new please wait 2-3 Hours, it will automatically start showing ads.
About this issue google say:
"It could be that you have only recently created a new Ad Unit ID and
requesting for live ads. It could take a few hours for ads to start
getting served if that is that case. If you are receiving test ads
then your implementation is fine. Just wait a few hours and see if you
are able to receive live ads then. If not, can send us your Ad Unit ID
for us to look into."
So you have to wait for a few hours.
Check Out Referance
2. After that if still does not started showing ads, probably you forgot to setup payment settings. So You have to complete that.
i use this for testing an ad
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.setRequestAgent("android_studio:ad_template").build();
adView.loadAd(adRequest);
and in the ads xml (banner test id)
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
if you want to test your own ad you have to change the id and the tag on setRequestAgent
.setRequestAgent("myapp").build();
Is it possible to load ads of Ad mob in starting of app and then use it in any button of whole project?
After click of any button it open quickly on every type of internet mainly on 2g
without taking time to load
it not a recommended way to show ads at start of the application as it result in poor user experience, like user might be interacting with your app and suddenly Ad pops up.
well if you still want to you can display it by overriding onAdLoad listener in your Activity's onCreate
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.interstitialAd_id));
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
UPDATE:
With this method it will only display it if its loaded
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
public void adShow() {
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-581420244534656/2222222");
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
requestNewInterstitial();
reseter();
}
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
requestNewInterstitial();
reseter();
}
});
}
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("3D9834hiqewuiry48937498urequE")
.build();
mInterstitialAd.loadAd(adRequest);
}
}
I have tested the use of interstitial in my app using the default ad from google and it's working but now what must i do to make sure that the default orange ad is not displayed to users when I publish my app? I already have the AdUnitId.
So long as you have set a valid Ad unit id from the ad provider you're using, you should get real ads. The reason you most likely aren't seeing real ads is because of the line .addTestDevice("3D9834hiqewuiry48937498urequE") which basically says "Only show me the default orange ad on this device".
So, if you always test your app on the same device, this line is disabling real ads from appearing while you test (which is what you want). But this line will only disable real ads on a single device, the one you're using. On other devices, users will see real ads.
Iam trying to display ad using Admob,but Iam not getting any call at onAdloaded.Can someone help...
Iam displaying an inerstitial ad.Iam setting and then Iam trying to load it...
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
CalligraphyConfig.initDefault(getString(R.string.font_alegreya_sans_regular));
setInterstitialAd();
setContentView(R.layout.splashscreen_activity);
}
private void setInterstitialAd() {
mInterstitial = new InterstitialAd(this);
mInterstitial.setAdUnitId(INTERSTITIAL_AD_ID);
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
mInterstitial.loadAd(adRequest);
mInterstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
displayInterstitial();
}
#Override
public void onAdFailedToLoad(int errorCode) {
}
});
}
private void initAdView() {
AdView mAdView = (AdView) findViewById(R.id.ad_container_layout);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
You should'nt have displayInterstitial() inside onAdLoaded(). This is causing the outcome of Ad not being shown. Either show an Ad after some level or user made action like after five level, one is displaying an interstitial, it comes in the pause menu. you keep it loaded from before and display it on the fifth level. or you can have it in that pause menu after some amount of time using a timer ( in which displayInterstitial() ) is included.
Suraj, add some log into both callback methods. One of them will be called.
I suspect the ad request is failing for reason, so onFailedToLoad() will be getting called instead.
Also DON'T call displayInterstitial() from onAdLoaded(). This causes really poor user experience and is likely to get your Admob account banned.
My question is that Admob Interstitial ad is displaying in testing mode but if app is released then ad is not displayed.
like i use
AdRequest mAdRequest;
mAdRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
`enter code here`.addTestDevice("12312132654654232").build();
but at the time releasing app i used code like this-
AdRequest mAdRequest;
mAdRequest = new AdRequest.Builder().build();
enter code here
this line not show ad.
Did you use these line in your code
first...
private InterstitialAd interstitial;
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(MY_AD_UNIT_ID);
then use this lines of code
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
and whenever you want to show add call this method
// Invoke displayInterstitial() when you are ready to display an interstitial.
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
hope this will help you.