Add ads to android game no xml - java

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);

Related

AdMob shows real ads even when using a test unit id; Android

TLDR: I get real ads even if I use a sample unit id provided by Google for testing.
I implemented native ads in my application.
I am using the Native Advanced sample ad unit as described here:
https://developers.google.com/admob/android/test-ads
However, the ads I get look very real, even though they have a "Test Ad" text in the title, and they also redirect me to real company websites. This has not happened with banner ads, I only got Google sample ads previously (e.g. Nice job, this is a test ad).
Some of the ads are coming from well-known restaurants in my country, and clicking on them navigates me to their website. I don't use my own unit id anywhere.
This is the code I use to initialize ads.
public static final String UNIFIED_AD_UNIT_ID = "ca-app-pub-3940256099942544/2247696110";
MobileAds.initialize(context, initializationStatus -> {
});
AdLoader adLoader = new AdLoader.Builder(context, UNIFIED_AD_UNIT_ID)
.forUnifiedNativeAd(unifiedNativeAd -> {
populateNativeAdView(unifiedNativeAd, nativeAdView);
}).build();
adLoader.loadAd(new AdRequest.Builder().build());
}
Is this a bug, or am I doing something wrong? (Or are these really test ads?) I really don't want to get banned from AdMob.
If you start your App running Android Studio, you can get the test device id for your device from the logcat at the bottom of Android Studio. Add this to your builder. By the way, the ads you are getting are looking like they should.

What is the difference between the id you get from logcat and AdRequest.DEVICE_ID_EMULATOR for testing?

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.

YouTubeEmbededPlayer GWT HowTo stop videos?

I am trying to use the youtube video gwt api.
The youtube-player works but how can I stop videos? I didnt find a command for that...
I created my player following:
protected YouTubeEmbeddedPlayer _youTubeEmbeddedPlayer;
_youTubeEmbeddedPlayer = new YouTubeEmbeddedPlayer(youTubeVideoID);
That´s the YouTube Player:
https://code.google.com/p/gwt-youtube-api/wiki/EmbededPlayer
By using YouTubePlayerWrapper.
You can stop video by calling the method
youTubePlayerWrapper.stopVideo();
This answer may not resolve the problem mentioned with the same library. In fact I tried multiple different library with every library having some issues. So end up creating my own wrapper. I have made it public check it if you can use it https://github.com/pandurangpatil/gwt-youtube

adding more textviews for every xml tag on android

i'm pretty new to android programming and i'm try to read an xml file. that all works fine, and i can see in the logCat that he is receiving all the data but the app only shows 5 of the tag from the xml file. so i was wondering if i could add some sort of string that will add a new textView/listView or what ever view i need.
There is a good Android API guide on this:
http://developer.android.com/guide/topics/ui/layout/listview.html

basic Activity starting

I'm having some problems here with basic Activity starting
I've tried to use the method below:
private void startAC() {
Intent i = new Intent(this, WordSendingActivity.class);
startActivity(i);
}
And while debugging I got some "Source not found" errors which claim that the source attachment does not contain the source for the file: Instrumentation.class, InvocationTargetException.class, Binder.class (in this order)
I got these different class names by trying Run->Step Return
What am I doing wrong here? I just want to preform a basic activity start, how would you do it better?
took me hours to give up my pride and come here :)
I hope my question is clear enough...
It looks like you might be attempting to "Step Return" into built-in classes. Android classes don't have sources available for debugging. They are binary-only classes in the respective android.jar.
The code for starting the activity looks fine. Are you sure you added WordSendingActivity to the AndroidManifest.xml ?

Categories

Resources