question

megadev avatar image
megadev asked

Amazon Mobile Ads and Open FL

Hey everyone, I'm sure someone else out there has done the same, but I'm trying to get Amazon Mobile Ads integrated with a game developed in Open FL and have come across an issue. I'm very nearly there, but I'm having trouble getting the ads to display over the game - I'm getting the ads to appear over a black background, but the game itself doesn't start. I'm assuming this is because I'm doing something wrong with the views. Here's what my onCreate function looks like: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AdRegistration.setAppKey(xxxxxxxxxxxxxxxxxxxxxxxxxx); AdRegistration.enableLogging(true); AdRegistration.enableTesting(true); adView = new AdLayout(this); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); adView.setLayoutParams(lp); linearLayout.addView(adView); adView.setListener(this); setContentView(linearLayout); adView.loadAd(new AdTargetingOptions()); } Does anything seem particularly wrong there? I'm guessing I need to add the adView over the top of the current view, but I can't quite get my head around it. If anyone has any pointers then I'd be interested to hear them! Thanks for reading. :) Cheers, Mike.
mobile ads
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Megadev, Yes, there is a mistake I can see in your code You did not add your apps view in the layout set in the activity. LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); adView = new AdLayout(this, AdSize.SIZE_600x90); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(600, 90); adView.setLayoutParams(lp); [b]linearLayout.addView(adView);[/b] try { AdRegistration.setAppKey(APP_KEY); } catch (Exception e) { Log.e(LOG_TAG, "Exception thrown: " + e.toString()); return; } View appView = findViewById(R.layout.main); l[b]inearLayout.addView(appView);[/b] setContentView(linearLayout); adView.loadAd(new AdTargetingOptions());
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

megadev avatar image
megadev answered
Hey Sujoy, Thanks for replying - I think I'm getting a little closer now, although I'm still stuck. One way of integrating Java functions in Open FL is to edit the GameActivity.java template, which I've done, like so: protected void onCreate (Bundle state) { super.onCreate (state); activity = this; mContext = this; mHandler = new Handler (); mAssets = getAssets (); metrics = new DisplayMetrics (); getWindowManager ().getDefaultDisplay ().getMetrics (metrics); mView = new MainView (getApplication (), this); //setContentView (mView);// No longer needed? // Amazon Ads AdRegistration.enableLogging(true); AdRegistration.enableTesting(true); linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); adView = new AdLayout(this, AdSize.SIZE_600x90); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(600, 90); adView.setLayoutParams(lp); linearLayout.addView(adView); AdRegistration.setAppKey(APP_KEY); linearLayout.addView(mView); setContentView(linearLayout); adView.loadAd(new AdTargetingOptions()); } This compiles and runs fine, but now I'm not seeing the ad at all, although I can see the game - I think I'm getting confused with regards to how "views" work in Android. What I'm trying to do above is create a new LinearLayout in code, add the adView and main view (mView) to it, setContentView to the linear layout, then load an Amazon ad. Does that sound about right or have I missed something? Cheers, Mike.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Bipin@Amazon avatar image
Bipin@Amazon answered
Is there a error in the Logcat . Ad failed to load kinds, Can you give us the error code and response
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

megadev avatar image
megadev answered
I finally figured out what was going on - it turns out there was an issue with my AndroidManifest.xml; this line... ...was within another activity when it should have been outside of course. So the "application" section ended up looking like this: I doubt that'll help anyone, but thanks for all your time - I've now submitted our game with Amazon Ads. :) Cheers, Mike.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.