Closed Zee-2 closed 9 months ago
That is a valid thought. I am not maintaining this application, other than making mandatory version updates. I can look into updating this, but may take some time.
In the meantime if you have worked on any changes, send me a PR.
I have implemented it, but I cannot make it work perfectly. Also, my code is not stable so PR is not recommended here.
In my case, the Interstitial Ad shows when we click on the "+" sign button for the sticker pack in StickerPackListActivity.java
, but also the dialog box of WhatApp for adding stickers also shows up at the same time on top of that interstitial ad, which violates Admob rules.
Because i was following a tutorial, hence i have not modified you code, just commented it, and implemented new code. I also commented the Interstitial Ads code in StickerPackListAdapter.java
. I think this will be easy for you to understand as the new implementation looks a lot similar to the deprecated one. So I am providing you the reference code from StickerPackListActivity.java
which i added.
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
private InterstitialAd mInterstitialAd;
private void initAd() {
// Commented deprecated code that was here (Only for Interstitial Ads)
loadInterstitialAd(); // New Implementation
}
private void loadInterstitialAd() {
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(this,getResources().getString(R.string.google_admob_interstitial_id), adRequest,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
// The mInterstitialAd reference will be null until
// an ad is loaded.
mInterstitialAd = interstitialAd;
Log.i(TAG, "onAdLoaded");
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
// Handle the error
Log.d(TAG, loadAdError.toString());
mInterstitialAd = null;
}
});
}
private void interstitialAdCallBacks() {
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){
/*@Override
public void onAdClicked() {
// Called when a click is recorded for an ad.
Log.d(TAG, "Ad was clicked.");
}*/
/*@Override
public void onAdImpression() {
// Called when an impression is recorded for an ad.
Log.d(TAG, "Ad recorded an impression.");
}*/
@Override
public void onAdDismissedFullScreenContent() {
// Called when ad is dismissed.
// Set the ad reference to null so you don't show the ad a second time.
Log.d(TAG, "Ad dismissed fullscreen content.");
mInterstitialAd = null;
}
@Override
public void onAdFailedToShowFullScreenContent(@NonNull AdError adError) {
// Called when ad fails to show.
Log.e(TAG, "Ad failed to show fullscreen content." + adError);
mInterstitialAd = null;
}
@Override
public void onAdShowedFullScreenContent() {
// Called when ad is shown.
Log.d(TAG, "Ad showed fullscreen content.");
}
});
}
// This is not part of new implementation (Obvious)
private final StickerPackListAdapter.OnAddButtonClickedListener onAddButtonClickedListener = pack -> {
// Commented deprecated code that was here for Interstitial Ads
// New Implementation
if (mInterstitialAd != null) {
interstitialAdCallBacks();
mInterstitialAd.show(this);
} else {
Log.d("TAG", "The interstitial ad wasn't ready yet.");
}
};
Thank you for the code sample and analysis, let me take a look. Give me a few days.
Actually I had some time to look at this tonight, and did refer the following links from googleads to get an idea
I guess the earlier Interstitial implementation was outdated and not updated with the last round of SDK updates since it was commented out and not used.
Anyways, the Ad specific code are updated in the class AdResources
, so that it can be reused from other Activities and provides an abstraction to interact with the Google Ads methods.
This seems to be working when tested in Emulator from a dev branch. Note that this is setup to trigger when the + button is clicked on the StickerPackListActivity
.
Interesting to note that the Interstitial ads do not show up all the time, it is cleared after an ad is shown once as an Error is getting thrown saying "This ad was already shown". So a new ad is loaded in the background in those cases.
public void showInterstitialAd(final Activity context) {
if (null != interstitialAd) {
interstitialAd.show(context);
} else {
// Get a new ad and then show it
final AdLoadedCallback callback = (AdLoadedCallback) context;
initInterstitial(context, callback);
callback.onAdFailedToShowFullScreenContent(NO_AD_ERROR);
}
}
I was also facing the issue, that the Ad load only once per session, weird behavior. It's great that you figured out the solution.
Thank you for taking a look into this issue.
Its recommended that this interstitial ad show up in both cases, one for the "+" button in StickerPackListActivity.java
and the second one is for ADD TO WHATSAPP button in StickerPackDetailsActivity.java
, as these are the two possible ways for the user to add stickers.
It is also a recommendation that i have seen in many sticker apps, that "+" button, instead of showing a dialog for adding stickers to WhatsApp, opens the pack details. This way the revenue can be increased as users will watch more banner ads.
Interstitial ad implementation has been updated and for reference enabled on StickerPackListActivity
.
I have found that your app has deprecated code for AdMob Interstitial Ads, which must be updated to get the Interstitial Ads work for newer Google Mobile Ads SDK version.
Also, for these types of apps which users use only once, for adding sticker to WhatsApp, the revenue with only the banner ads are obviously very less. Hence the Interstitial Ads should be enabled by default, as its code is currently commented in project. To avoid bad experience by user due to Interstitial Ads, we can reduce the no. of times it shows to user or any other ways.
Thanks