CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
08/02/14 11:12 PM (10 years ago)

Android Amazon ads integration (interstitials)

Whatever cpm means, amazon is having a special deal for august and september. A guaranteed $6 cpm. They payout anything above 2 bucks I believe.anyway.. first add this next to your other variables(right above the onCreateView method): private InterstitialAd interstitialAd; then in the onCreateView method of whatever plugin you want this in,right under the code that inflates the layout: (View thisScreensView = inflater.inflate(R.layout.cm_androidaviary, container, false);) add this //Your get your app key after creating it in amazon store AdRegistration.setAppKey("849999968494979656496499"); // Create the interstitial. this.interstitialAd = new InterstitialAd(getActivity()); // Set the listener to use the callbacks below. this.interstitialAd.setListener(new MyCustomAdListener()); // Load the interstitial. this.interstitialAd.loadAd(); then anywhere outside of the onCreateView method,after this line : }//onCreateView... paste this: class MyCustomAdListener extends DefaultAdListener { @Override public void onAdLoaded(Ad ad, AdProperties adProperties) { if (ad == CM_androidAviary.this.interstitialAd) { // Show the interstitial ad to the app's user. // Note: While this implementation results in the ad being shown // immediately after it has finished loading, for smoothest user // experience you will generally want the ad already loaded // before it’s time to show it. You can thus instead set a flag // here to indicate the ad is ready to show and then wait until // the best time to display the ad before calling showAd(). CM_androidAviary.this.interstitialAd.showAd(); } } @Override public void onAdFailedToLoad(Ad ad, AdError error) { // Call backup ad network. } @Override public void onAdDismissed(Ad ad) { // Start the level once the interstitial has disappeared. } } On this line above,in the if statement: (ad == CM_androidAviary.this.interstitialAd) the "CM_androidAviary" part is the name of the java file Im putting this code into. So Im doing it in CM_androidAviary.java. Therefore change it to whatever java file your inserting this code into. Do that in both instances of the file name. you must also add this to your manifest: <activity android:name="com.amazon.device.ads.AdActivity" android:configChanges="keyboardHidden|orientation|screenSize"/> and also add the amazon ads jar file from the downloaded amazon sdk: https://developer.amazon.com/public/apis/earn/mobile-ads/docs/quick-start this is just to show interstitial.maybe ill try the banners later, I dont know,but good night!
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
08/04/14 02:52 AM (10 years ago)
Have you had a chance to play with banner ads yet.
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
08/04/14 05:16 AM (10 years ago)
I havent yet but plan to today. I also want to rrytheir ads for iOS
 
pimentazores
Aspiring developer
Profile
Posts: 47
Reg: Mar 26, 2013
Barcelona
8,020
like
08/04/14 06:54 AM (10 years ago)
I will try it, tks!
 
pimentazores
Aspiring developer
Profile
Posts: 47
Reg: Mar 26, 2013
Barcelona
8,020
like
08/04/14 12:09 PM (10 years ago)
I will try it, tks!
 
pimentazores
Aspiring developer
Profile
Posts: 47
Reg: Mar 26, 2013
Barcelona
8,020
like
08/15/14 12:46 PM (10 years ago)
Hi CMCOFFEE!, Did you try with amazon banner ads? I'm having troubles with it..
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
08/16/14 07:25 AM (10 years ago)
I forgot.i will try today for sure
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
08/16/14 06:57 PM (10 years ago)
For the banner ads: in my xml layout file I added this: <com.amazon.device.ads.AdLayout android:id="@+id/adview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" > </com.amazon.device.ads.AdLayout>\ Then in the certain plugins java code I did this: Add this under the other variables: private AdLayout adView; Then under the code that inflates the layout, Looks something like this View thisScreensView = inflater.inflate(R.layout.cm_voicesearch, container, false); I added this: AdRegistration.setAppKey("1234567953258856665555522"); this.adView = new AdLayout(getActivity()); this.adView = (AdLayout) thisScreensView.findViewById(R.id.adview); AdTargetingOptions adOptions = new AdTargetingOptions(); // Optional: Set ad targeting options here. this.adView.loadAd(adOptions); Then if your plugin has the onDestroy method add this line in it: this.adView.destroy(); If the plugins java file didnt come with the onDestroy method, copy and paste the below method outside the OnCreateView method @Override public void onDestroy() { super.onDestroy(); this.adView.destroy(); }
 
Ivelin
I hate code!
Profile
Posts: 19
Reg: Feb 05, 2014
Alva
190
like
09/08/14 05:31 PM (9 years ago)
@CMCOFFEE, I tried to implement the amazon ads however, I get a message that says: AdLayout cannot be resolved to a type and AdTargetingOptions cannot be resolved to a type. Could you please help me with it? Thank you
 
Ivelin
I hate code!
Profile
Posts: 19
Reg: Feb 05, 2014
Alva
190
like
09/08/14 06:11 PM (9 years ago)
I fixed it somehow. However, the ads do no show at all. Do I need to have the amazon library in the libs folder? Any suggestions, Please?
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
09/08/14 08:09 PM (9 years ago)
Yes I you need to add the admob jar file to the libs folder.then when red errors show on AdLayout and AdTargetingOptions, put your mouse over those red underlined words, and suggestions will pop up.Click the message about "importing"
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.