i am playing around with flavors in Android studio, i made one demo and one full flavor, the sole difference beeing the demo version having a copy of the activity_main.xml layout with an admod view in it,
the full version has not....
i read that having separate java class files is a bad idea, so i integrated the admob stuff in the main/.../src/java/.../MainActivity class:
if("free".equals(BuildConfig.FLAVOR))
{
Log.d(TAG, "flavor: " + BuildConfig.FLAVOR);
MobileAds.initialize(this, ADMOB_APP_ID);
AdView mAdView;
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice("151A597D874BD0B8D69D5D5E5B18B0E8")
.build();
mAdView.loadAd(adRequest);
}
and building the demo version goes flawlessly....
but, since the admob view id doesn't exist in the full version, well it doesn't build anymore....
quitting with a
Error:(204, 34) error: cannot find symbol variable adView
so i am a bit at a loss how to solve that... all the examples about flavors i read through, adress the problem generally, but for solving specifically that sort of problem i couldn't find anything....
You must to use only one xml file (activity_main.xml) and use
AdView mAdView;
mAdView = findViewById(R.id.adView);
if("free".equals(BuildConfig.FLAVOR))
{
mAdView.setVisibility(View.VISIBLE);
mAdView.loadAd(adRequest);
}else{
mAdView.setVisibility(View.GONE);
}
Related
I have seen that recently a new warning has appeared in mi project in the following line:
AdRequest adRequest = new AdRequest.Builder().build();
The warning is in "new AdRequest.Builder().build();"
This is the warning:
This method should only be accessed from tests or within private scope
I don't understand why this warning is showing, could it be a bug or something like that?
I have the same issue, and added
#SuppressLint("VisibleForTests")
AdRequest adRequest = new AdRequest.Builder().build();
It is NOT a good solution, but it made the warning go away and the adds seem to work.
I'm still testing my app ads and I use this code to generate test ads.
But I was wondering if there is any difference between using AdRequest.DEVICE_ID_EMULATOR and using the id generated in logcat?
Code I'm using
adLoader.loadAd(new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build());
I would so encourage to just use test ads provided by Google.
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(BuildConfig.DEBUG ? "ca-app-pub-3940256099942544/6300978111" : "yourRealAdUnitID");
So much simpler than messing around with multiple test devices.
I tried implementing Native Express Ads, but for testing purposes i can't find the test ad id.
I found alot of posts which just used the test id for banner ads ca-app-pub-3940256099942544/6300978111and for some reason this does work.
Now my question is if Native Express Ads are still recommended to use as an ad type or are they deprecated and should i switch to Native Advanced Ads?
My code
LinearLayout adContainer = findViewById(R.id.adContainer);
mAdView = new NativeExpressAdView(getApplicationContext());
mAdView.setAdSize(new AdSize(320,50);
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
adContainer.addView(mAdView);
LinearLayout adContainer2 = findViewById(R.id.adContainer2);
mAdView2 = new NativeExpressAdView(getApplicationContext());
mAdView2.setAdSize(new AdSize(320,50);
mAdView2.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
adContainer2.addView(mAdView2);
AdRequest adRequest = new AdRequest.Builder().addTestDevice("4EF772AE9549741BE0E1FCA236C7382C").build();
mAdView.loadAd(adRequest);
mAdView2.loadAd(adRequest);
Yes you are right now google has replaced Native Express Ads with Native Advanced Ads.
Here is the official link of Google Admob documentation
https://developers.google.com/admob/android/native/advanced
So I made a game that I'm trying to add ads to but I'm not using any XML. I found two examples that say they should work after extensive research and many hours of looking. How ever even when I try implementing that code I still get errors and am at a loss.
I've searched through stack overflow and many other sites and I am at a loss. Ive tried implementing this several different ways and I'm not sure if I'm not including ti right or what.
Here are the two remaining errors I'm getting:
The Constructor is not working for the AdView class the way its described in the tutorial and I'm not sure how to fix that.
and the AdRequest() function says its implemented as private and even when i try to use the AdRequest().Builder().build(); it still gives the same error.
I have no xml in my code and am using a class that extends SurfaceView for the entire game, and i am using AdMob ads. How do i do this with out xml?
Here is how I load my ads. Hope it helps.
admobAdView = new com.google.android.gms.ads.AdView(getActivity());
admobAdView.setAdSize(AdSize.SMART_BANNER);
admobAdView.setAdUnitId("ca-app-pub-###########/#######");
adViewContainer = (ViewGroup) getView().findViewById(R.id.ad_view_group);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("#################")
.build();
admobAdView.loadAd(adRequest);
I have a working AdMob AdView on top of my opengl game. Its working great but I notice that it keeps showing a particular blank ad. I thought it was a bug on my side but then I noticed that the ad is functioning partially. The ad appears to be a RocketFuel ad according to the provided info button in the top right of the AdView. Clicking within the blank AdView area does nothing unless the info button it hit. The images and code below help explain.
I thought RocketFuel was a separate ad service, is it possible to limit its appearance in Google AdMob using the Filter Settings > Category / Type Settings > Affiliate offers? Or perhaps one of the other categories? I am going to try adding a URL Block for rocketfuel.com under the Ad Filters. However I am unsure if they are serving ads directly from their domain.
Otherwise, is there any way to block, report, or limit these types of ads from being shown through my app? Has anyone had similar problems with such ads?
Here is how I slap the adview on top of my java based OpenGL ES 2 renderer:
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mView = new nopgRenderer(this);
setContentView(mView);
adView = new AdView(this, AdSize.IAB_LEADERBOARD, "<AdMobAdAppID>");
RelativeLayout layout = new RelativeLayout(this);
layout.addView(adView);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
adView.setLayoutParams(params);
this.addContentView(layout, params);
adView.loadAd(new AdRequest());
}
public static void hideAd(){
adView.setVisibility(AdView.GONE);
}
public static void showAd(){
adView.setVisibility(AdView.VISIBLE);
}
The app on Google Play:
https://play.google.com/store/apps/details?id=com.dmtsource.nopg
Example of a normal ad:
Example of the blank ad:
Clicking on the info item in the blank ad: