I have published an app in google play having the ad in it, few days ago I got the following email from google Admob.
We are alerting you that your app is currently in violation of the AdMob program policies. Importantly, this will require action on your part to ensure no disruption in ad serving. Please read below for more information on the actions you need to take:
LAYOUT ENCOURAGES ACCIDENTAL CLICKS - INTERSTITIAL ADS:
Publishers are not permitted to encourage users to click AdMob interstitial ads in any way. This includes any implementation that may encourage accidental clicks, such as placing an interstitial ad in a way that prevents viewing the app’s core content or placing an interstitial ad in a way that interferes with navigating or interacting with the app’s core content and functionality.
Please review how you’ve implemented interstitial ads and be mindful of the following common examples of non-compliant implementations:
Interstitial ads that appear before the app has opened or after the app has closed.
Interstitial ads that are triggered after a user closes another interstitial ad.
Interstitial ads loading unexpectedly while a user is viewing the app’s content. Remember to only serve interstitials between pages of content.
Interstitial ads that trigger after every user click.
Interstitial ads that appear during periods of game play or heavy user interaction.
Now below is my MainActivity. I need help to place the ad in appropriate area
public class MainActivity extends Activity {
private InterstitialAd interstitial;
// static int p;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
mViewPager.setAdapter(new TouchImageAdapter());
mViewPager.setCurrentItem(5);
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("xxxxxxxxxxxxxxxxxxxxxxxx");
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) this.findViewById(R.id.adView);
// Request for Ads
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("")
.build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
// Load ads into Interstitial Ads
interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {
interstitial.show();
}
}
class TouchImageAdapter extends PagerAdapter {
private int[] images = { R.drawable.file_page05,R.drawable.file_page04,R.drawable.file_page03,R.drawable.file_page02,R.drawable.file_page01};
#Override
public int getCount() {
return images.length;
}
#Override
public View instantiateItem(ViewGroup container, int position) {
TouchImageView img = new TouchImageView(container.getContext());
img.setImageResource(images[position]);
container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
return img;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
}
Creating ad will take some time. You are displaying the ad after the viewpager is displayed. This will lead to a case where the user is navigating through viewpager and suddenly ad is loaded. This is against the ad policy.
Before loading the viewpager, you have check whether ad is loaded. If ad is loaded, then display ad and on closing the ad, display viewpager. Else directly display viewpager.
I will usually load the ad in the launcher activity and display when needed.
Related
I want integrated AdMob into my app. but here is an issue we manually need to reload Ad for showing. I want to try when some close/Dismiss the Ad automatically load again that I called it again onAdDissmissed method. Is this a policy violation? or Is a good programming practice or not?
Here my code oncreate method
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
loadMethodAdMob();
}
load Method
public void loadMethodAdMob() {
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(this, AD_UNIT_ID, adRequest, new InterstitialAdLoadCallback() {
#Override
public void onAdLoaded(#NonNull InterstitialAd interstitialAd) {
// will be null until an ad is loaded.
MyActivity.this.interstitialAd = interstitialAd;
mToast("Ad Loaded");
interstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
#Override
public void onAdDismissedFullScreenContent() {
MyActivity.this.interstitialAd = null;
mToast("The ad was dismissed.");
InterstitialAdMob(); // i called it here is this ok
}
#Override
public void onAdShowedFullScreenContent() {
mToast("The ad was shown.");
}
});
}
});
}
button click
public void buttonClickShowAd(){
if (interstitialAd != null) {
interstitialAd.show(this);
} else {
mToast("Ad did not load");
requestForReload();
}
}
You can load n-number of interstitial ads in advance so that it will be available when show method is called. Above code is perfectly fine.
Reference - https://developers.google.com/admob/android/interstitial#some_best_practices
Allow for adequate loading time.
Just as it's important to make sure you display interstitial ads at an appropriate time, it's also important to make sure the user doesn't have to wait for them to load. Loading the ad in advance by calling load() before you intend to call show() can ensure that your app has a fully loaded interstitial ad at the ready when the time comes to display one.
Don't flood the user with ads.
While increasing the frequency of interstitial ads in your app might seem like a great way to increase revenue, it can also degrade the user experience and lower clickthrough rates. Make sure that users aren't so frequently interrupted that they're no longer able to enjoy the use of your app.
However you might also want to check Disallowed interstitial implementation policy when you load multiple objects in advance.
https://support.google.com/admob/answer/6201362?hl=en
As we know, google requires us to use test device and test ad unit id, when we develop the app. However, I want to know that if there exists anyway that I can
see the real ad, because I am afraid that no ad will show after I change the code and ad id before release. I have successfully seen test ad, and then I changed the code and ad id, and then submit my app to beta testing, but the tester said that no ad was shown, is it normal, or I have made some mistake in my code or ad unit id.
Thank you for your help!
Below is my ad-related code, and I have changed the ad id
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
You can use actual ad unit id even for development, but your test devices should be added to the list of TEST DEVICES when you build your ad request.
If it's a valid ad unit id that you are using, you can be sure that ads will appear when you publish your apps. Also, you can check if you are getting hits for your ad unit in Adsense Dashboard.
If you want to be dead sure, you can just try to install the apk on another device, test it, and then publish it when you see the ads.
You can use AdListener and monitor why it is not showing ads . Remember if you have created fresh ad units then it will take some time or few hours to arrange live ads for it . If test ads are showing and you have valid ad unit id and also your app has not violated any policy then you are good to go (You will be emailed if your app have a policy issue) . Ads will be shown when availabe.
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest1 = new AdRequest.Builder().build();
adView.loadAd(adRequest1);
adView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
Log.i("Ads", "onAdLoaded");
}
#Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
switch (errorCode){
case AdRequest.ERROR_CODE_INTERNAL_ERROR:
Toast.makeText(PlayListsActivity.this,"onAdFailedToLoad banner ERROR_CODE_INTERNAL_ERROR",Toast.LENGTH_SHORT).show();
break;
case AdRequest.ERROR_CODE_INVALID_REQUEST:
Toast.makeText(PlayListsActivity.this,"onAdFailedToLoad banner ERROR_CODE_INVALID_REQUEST",Toast.LENGTH_SHORT).show();
break;
case AdRequest.ERROR_CODE_NETWORK_ERROR:
Toast.makeText(PlayListsActivity.this,"onAdFailedToLoad banner ERROR_CODE_NETWORK_ERROR",Toast.LENGTH_SHORT).show();
break;
case AdRequest.ERROR_CODE_NO_FILL:
Toast.makeText(PlayListsActivity.this,"onAdFailedToLoad banner ERROR_CODE_NO_FILL",Toast.LENGTH_SHORT).show();
break;
}
Log.i("Ads", "onAdFailedToLoad");
}
#Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
Log.i("Ads", "onAdOpened");
}
#Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
Log.i("Ads", "onAdLeftApplication");
}
#Override
public void onAdClosed() {
// Code to be executed when when the user is about to return
// to the app after tapping on an ad.
Log.i("Ads", "onAdClosed");
}
});
I am developing and android application that needs to show Facebook Banner Ads, for that i have successfully generated Placement id and implemented the code suggested by Facebook developers website. But the problem is that ads are not showing. On debugging i find out this No Fill Error. I have searched this error on google but could not able to solve it. Any help will be appreciated. Here is my code :
AdView adView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Instantiate an AdView view
adView = new AdView(this, PLACEMENT_ID, AdSize.BANNER_HEIGHT_50);
// Find the main layout of your activity
LinearLayout layout = (LinearLayout)findViewById(R.id.activityLayout);
// Add the ad view to your activity layout
layout.addView(adView);
adView.setAdListener(new AdListener() {
#Override
public void onError(Ad ad, AdError error) {
// Ad failed to load.
// Add code to hide the ad's view
}
#Override
public void onAdLoaded(Ad ad) {
// Ad was loaded
// Add code to show the ad's view
}
#Override
public void onAdClicked(Ad ad) {
// Use this function to detect when an ad was clicked.
}
});
// Request to load an ad
adView.loadAd();
}
After lots of searching i find out the solution why ads are not showing, actually my application is not live(in google play store) so try to login on your application with that Facebook account through which Placement id is generated. It will work.
My application opens a Publisher InterstitialAd whenever you start but when a user closes it reopens. This process happens constantly and then you can't use application, can anyone help me?
public void getIntertitalAds(boolean isPortraitMode)
{
interstitial = new PublisherInterstitialAd(context);
if(isPortraitMode)
interstitial.setAdUnitId(tags.getAdUnitInterstitial());
else
interstitial.setAdUnitId(tags.getAdUnitInterstitialTablet());
AdListener adListener = new AdListener() {
#Override
public void onAdLoaded() {
super.onAdLoaded();
if(interstitial!=null)
interstitial.show();
}
#Override
public void onAdClosed() {
super.onAdClosed();
interstitial = null;
}
};
// Create ad request.
PublisherAdRequest adRequest = new PublisherAdRequest.Builder()
.build();
// Begin loading your interstitial.
interstitial.setAdListener(adListener);
interstitial.loadAd(adRequest);
}
NEVER call interstitial.show() from AdListener#onAdLoaded(). You have no control over when it will be called and it presents a really poor user experience. Instead call interstitial.show() at a natural break point in your app.
There is no need to have separate AdUnitIds for portrait and landscape. Interstitials are the same regardless.
All the code in your getIntertitalAds() (sic) method should be Activity#onCreate
I strongly suspect your problems stem from a combination of 1 and 3.
I am trying to setup adMob ads. I have two questions:
1) Am I using adListener interface correctly?
2) How come I am unable to see ad Interstitials?
Lets start with the adListener. As far as what I understood from the instructions, adListener is an interface. So I created an interface.
import com.google.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public interface AdListener {
public void onReceiveAd(AdView ad);
public void onFailedToReceiveAd(AdView ad, AdRequest.ErrorCode error);
public void onPresentScreen(AdView ad);
public void onDismissScreen(AdView ad);
public void onLeaveApplication(AdView ad);
}
Then in my main class I implemented AdListener, and once I did I was prompted to add unimplemented methods (all the methods from the interface).
public class MainActivity extends Activity implements AdListener {
// other code for the body (here). Just showing the methods and implement
#Override
public void onReceiveAd(AdView ad) {
Log.d(TAG, "onReceiveAd");
Toast.makeText(this, "onReceiveAd", Toast.LENGTH_SHORT).show();
}
#Override
public void onFailedToReceiveAd(AdView ad, ErrorCode error) {
Log.d(TAG, "onFailedToReceiveAd");
Toast.makeText(this, "onFailedToReceiveAd", Toast.LENGTH_SHORT).show();
}
#Override
public void onPresentScreen(AdView ad) {
Log.d(TAG, "onPresentScreen");
}
#Override
public void onDismissScreen(AdView ad) {
Log.d(TAG, "onDismissScreen");
}
#Override
public void onLeaveApplication(AdView ad) {
Log.d(TAG, "onLeaveApplication");
}
}
My reason for thinking this does nothing is that I am not receiving my logs. I added toasts to double confirm I was not missing something. I think there is another step I am missing for this to work.
Now for the ads part. I thought I followed the instructions well, and my banners work in fact. But my ad interstitials do not work. This is what I have for the banners and the interstitials.
Starting with code snippet from my xml for the banner
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="I_ADDED_CORRECT_ADUNIT_ID"
ads:adSize="BANNER" />
In my main Activity, I have the following code. Again, I want to see test ads:
// setup ad banner and interstitial
final TelephonyManager tm = (TelephonyManager)getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String testDeviceId = tm.getDeviceId();
Log.d(TAG, "testDeviceId retrieved(" + testDeviceId + ")");
// create interstitial
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("I_ADDED_CORRECT_ADUNIT_ID");
// ad banner
adView = (AdView)this.findViewById(R.id.adView);
// request test interstitial ads
AdRequest adRequestInterstitial = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(testDeviceId)
.build();
// request test banner ads
AdRequest adRequestBanner = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(testDeviceId)
.build();
//load interstitial ads
interstitial.loadAd(adRequestInterstitial);
displayInterstitial();
// load banner ads
adView.loadAd(adRequestBanner);
//NOTE: the above code is all in onCreate().
//diaplayInterstitial is outside of onCreate()
public void displayInterstitial() {
if (interstitial.isLoaded()) {
Log.d(TAG, "displayInterstitial()");
interstitial.show();
}
}
Lets see what else to tell you? Awww, yes! I also have the permissions already set in the manifest. Permissions = INTERNET, ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, READ_PHONE_STATE.
I went to project properties and added the google-play-services_lib
This is my whole setup! I have tried a number of things, because I had some 'feelings' about what may be the issue. First, I thought that maybe test ad banners and test ad interstitials cannot be requested at the same time. So I moved interstitial code to onStart(). But then, I was not sure if this was necessary, beneficial or worse (and it did not work!). My second thought was that everything works fine, and once I publish my app all will be good. But regardless, my logs are not working for the AdListener. If I can get that going, I think I can start verifying with more confidence of what is going on.
Thank you in advance for your help.
Log SS
OK, several problems here.
1) No you are not using the AdListener interface correctly.
Don't create your own interface. AdMob already supplies an AdListener interface. You do need to implement it however.
NB personally I would create an anonymous implementation of the AdListener instead of adding it to the Activity, but that's a design design for yourself.
Next you need to attach your listener to your AdView. So in your #onCreate
// load banner ads
adView.setAdListener(new AdListener() {
...
});
adView.loadAd(adRequestBanner);
2) You are unlikely to see any Interstitials with the code above because you are attempting to display immediately after requesting. It is extremely unlikely that an Interstitial has been downloaded in that short time frame. And in any case you really don't want to display an interstitial every time your Activity is created, it is a poor user experience.
Move your call to displayInterstitial() to some later point in your app life cycle, such at the end of a game session or between levels etc.
Last I looked at admob the interstitial ads were invite only. Meaning they would contact you if they felt your apps were a good fit with that type of advertising.