B4A Library Amazon Ad Wrapper

Just after I released this wrapper, Amazon changed their SDK function prototypes for the listeners. That change broke the wrapper. See post #20 in this thread for a modified version of the wrapper.

Hello,
I have attached a zip archive with a wrapper library for the Amazon Ads SDK. The zip archive includes the wrapper source code in Java, the compiled library jar and XML files, and a small test B4A application.

I based the wrapper on source code uploaded by Erel several years ago for the Admob wrapper merged with the Amazon SimpleExample. I used the Simple Library Compiler (SLC) to compile.

You will need to get an Amazon developer account, it's free, and an app ID. I just created a dummy test app entry to get the ID.

https://developer.amazon.com/public/

You also need to download the Amazon Ad SDK. I renamed it to amazon-ads.jar by removing the version number from the jar file name.

https://developer.amazon.com/public/resources/development-tools/sdk

The Amazon-ads.jar is buried in the SDK download. You have to open the SDK archive and extract amazon-ads-xxxx.jar library.

This jar (amazon-ads.jar) along with my AmznAd.jar and AmznAd.xml files from the attached zip archive should be placed in your B4A Additional Libraries directory. Your Amazon App ID needs to be entered in the B4A file.

I have tested this wrapper for two Amazon ad sizes, 320x50 and 300x250.

When you look at the wrapper Java source code and find major errors, please upload the fixes to this forum.

Barry.
 

Attachments

  • AmznAdTest.zip
    12.8 KB · Views: 353
Last edited:

Theera

Well-Known Member
Licensed User
Longtime User
Hi canalrun,
What is different from Admob? I know only,we can get free fee. I 'm not good at English.Whenever I must read more,I will be not understand. Thank you in advance.
 

canalrun

Well-Known Member
Licensed User
Longtime User
I don't know if Amazon is any better than Admob. It is just another option. Amazon recently advertised a guaranteed CPM for banner ads. Is this any good? – Don't know.

Barry.
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
In my experience, Amazon is significantly better than admob. The best combination I have found is to call Amazon first and if no ads are returned, then load an ad from Admob.
 

sagt3k

Member
Licensed User
Longtime User
Hi to everybody
Sorry, I hopeand I think I followed all the steps, but I encounter this problem when I run the app:

** Activity (main) Create, isFirst = true **
AMZNAds - Add Size: 320x50
** Activity (main) Resume **
java.lang.AbstractMethodError: abstract method not implemented
at canalrun.b4a.amznwrapper.AMZNWrapper$1.onAdFailedToLoad(AMZNWrapper.java)
at com.amazon.device.ads.AdController$3.run(AdController.java:612)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Thanks for your big support
 

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
Sorry I'm not much of a library developer. Hopefully somebody else can analyze this error.

Looking at the line:
at canalrun.b4a.amznwrapper.AMZNWrapper$1.onAdFailedToLoad(AMZNWrapper.java)

This seems to have to do with the failed load listener. This is a real long-shot - in your B4A code, do you have the event listener for:

B4X:
Sub advw_failedtoreceivead(err As String) ' replace advw with your initialize event name
  Log("error: " & err)
End Sub
I successfully use this wrapper for Amazon ads. I have gotten the error message for "failedtoreceivead".

Barry.
 

sagt3k

Member
Licensed User
Longtime User
Hi Barry
I think I've followed all the notes you esplicate.
1) I extrapolated from the AmazonSDK the file amazon-ads-5.3.9.jar and renamed and saved in the library B4A as amazon-ads.jar
2) I saved in the directory of library files B4A the files AmznAd.jar and AmznAd.xml
3) I'm using Java jdk1.7.0_21 and SDK Android-19

However, the program starts but then goes into error when executing "advw.LoadAd"
Where am I wrong?
Thanks for your great support
 

canalrun

Well-Known Member
Licensed User
Longtime User
executing "advw.LoadAd"

This rings a bell!

Using the new Admob 2.0 library from Erel I have had errors at the LoadAd function call if I run on devices less than android 2.3 (Erel does state that the Admob library only works on 2.3 and above). Maybe this error is similar.

Which version of android is on your device?
Try commenting out the LoadAd line to see if everything works properly.

If you have access to a different device, does that also fail?

Barry.
 

sagt3k

Member
Licensed User
Longtime User
I comment the line if the program works. but of course as soon as I press the button, it goes into error.
I'm trying with different versions of Android and SDK, always the same error.
Maybe I'm wrong in something in the libraries? Could you summarize all the steps for the libraries?
Thanks
 

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I'll try.

I think the easiest way to get things working is by trying the demo application included with the first post, ANZNAdTest.

From the zip file you'll need to copy the two files from the Libs folder into your B4A additional libraries directory.

Open the test app B4A code. In this app the first thing to notice is changes to the manifest. The following lines have been added using the manifest editor:

B4X:
'Amazon
AddApplicationText(
<activity android:name="com.amazon.device.ads.AdActivity"
  android:configChanges="keyboardHidden|orientation|screenSize"/>
)
'End of Amazon

On line 25 of AMZNAdTest.b4a you need to insert your own ad ID in the string. (Amazon calls it an Application Key)

To get an ad ID, open a developer account at Amazon. I use in the USA:
https://developer.amazon.com/public/

Once you have an account in the dashboard select "Add New App" to create a dummy app solely for the purpose of getting an ad ID. I named my dummy app AMZNAdTest. After creating an app you'll be able to copy the ad ID. It looks something like: 84c6xxxxxxxxxxxxxxxxxxxxxxxxxxxx. (The first 4 numbers will probably be different. The Xs represent numbers.)

Use this number as the adid string on line 25 in the B4A code.

I hope I haven't forgotten something. You should now be able to Compile & Run this test app on a device. Ads from Amazon should show although sometimes it can take a while before they start showing (maybe up to a few hours).

Hope this helps.
Barry.

Added later…

Sorry, I did forget to include a very important step in the directions above.

On the Amazon developer site there is an SDK that contains the amazon-ads-5.1.153.jar file (located in the SDK directory Android\Ads\lib\) implementing the Amazon ads interface.

This SDK should be downloaded and the jar file placed in the B4A additional libraries folder.

(I renamed amazon-ads-5.1.153.jar to amazon-ads.jar before placing in the B4A folder to shorten the name.)
 
Last edited:

sagt3k

Member
Licensed User
Longtime User
Hi Barry
hello, nothing to do
I followed everything that you have shown me. The last thing, could you send me your file amazon-ads.jar. Let's see if this is the problem?
However, I am attaching a immage error. I tried it on 2 different emulators and on Mobile Samsung S2 and S3. same error
Thanks image1.jpg
image1.jpg
 

Asmoro

Active Member
Licensed User
Longtime User
In my experience, Amazon is significantly better than admob. The best combination I have found is to call Amazon first and if no ads are returned, then load an ad from Admob.

Hi Jack,

Could you give us a snippet code or sample how you manage that?

Tia,
Asmoro
 

canalrun

Well-Known Member
Licensed User
Longtime User
Hi Jack,
Could you give us a snippet code or sample how you manage that?
Tia,
Asmoro

In the few weeks that I have used Amazon Ads, they seem pretty good, but the fill rate is less than Admob. I also would like to try using a combination of Amazon and Admob. A code snippet, or just a description of the logic you use to implement the combination would be very helpful.

Do you use the Amazon failed-to-load to indicate that you should load an Admob add?
Do you use Admob's pause and resume and/or visible and enabled properties to swap the two adviews?

Thanks,
Barry.
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
Hi Barry,

I have a list that has ad network priorities (such as "Amazon","Admob"). I track the current network in a global variable and have a sub for LoadAd. In the failed to load subs, I increment the integer that stores the current network and call LoadAd (which then determines which network to attempt to load the ads from). I also just remove the adview in the failed to load function.

Best regards,
Jack
 

GMan

Well-Known Member
Licensed User
Longtime User
You can make a timer an change the Advertiser with that
 

GMan

Well-Known Member
Licensed User
Longtime User
By testing the sample. always an error occured when compiling:

class file for amazon.......not found.
But in the archive is no class file.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I found out, in the last couple days, that Amazon changed some of the function prototypes in the latest versions of their library – I'm guessing to support the addition of interstitial ads. Of course this broke the wrapper.

The wrapper works with an older version of the Amazon library, amazon-ads-5.1.153.jar. But, it fails with newer versions of library.

I hope to have an updated wrapper in the next few days.

Barry.
 

GMan

Well-Known Member
Licensed User
Longtime User
Hoi Barry,

OK - Status: Loading.... ;)
 

canalrun

Well-Known Member
Licensed User
Longtime User
Note: As of Sept. 2020 this library is 6 years old. I've been informed that it no longer works correctly.

Hello,
Amazon modified their SDK and changed the function prototypes for their listeners. The change broke my original wrapper.

Amazon added interstitial ads to their SDK. This wrapper does not handle the interstitial ad type, although within the Amazon SDK there is a sample showing how to handle interstitial ads. I have included the eclipse project source code for this wrapper. A new wrapper could be created using this wrapper as a guide.

I have attached a zip archive to this post with my new wrapper library. The zip archive includes the wrapper source code in Java, the compiled wrapper jar and XML files, and a small test B4A application.

I based the wrapper on source code uploaded by Erel several years ago for the Admob wrapper merged with the Amazon SimpleExample found in the SDK. I used the Simple Library Compiler (SLC) to compile.

You will need to get an Amazon developer account, it's free, and an app ID. I just created a dummy test app entry to get the ID.

https://developer.amazon.com/public/

You also need to download the Amazon Ad SDK. The jar file you need is buried deep within the SDK. I tested with the latest version, amazon-ads-5.3.22.jar. I renamed the jar to to amazon-ads.jar by removing the version number from the jar file name.

https://developer.amazon.com/public/resources/development-tools/sdk

The Amazon-ads.jar is buried in the SDK download. You have to open the SDK archive and extract amazon-ads-xxxx.jar library.

This jar (amazon-ads.jar) along with my AmznAd2.jar and AmznAd2.xml files from the attached zip archive should be placed in your B4A Additional Libraries directory. Your Amazon App ID needs to be entered in the B4A file at source code line 25.

In this new version of the wrapper I call the Amazon ad object AmznAd2 (instead of AmznAd).

I have tested this wrapper for two Amazon ad sizes, 320x50 and 600x90.

I edited the example app using the new version 3.80 of B4A.

If you look at the wrapper Java source code and find major errors, please upload the fixes to this forum.

Barry.
 

Attachments

  • AmznAdTst2.png
    AmznAdTst2.png
    20.1 KB · Views: 254
  • AmznAdTest2.zip
    42.4 KB · Views: 340
Last edited:
Top