Search code examples
androidadsamazon-advertising-api

amazon ads xml layout


I am trying to include the ads by making them part of my xml layout, I noticed on this quickstart guide: https://developer.amazon.com/sdk/mobileads/quick-start.html it says that you should have the namespace as "xmlns:Amazon="http://schemas.android.com/apk/res/"". However when I tried this intelij says that the namepace is never used and the ad never shows up in the layout. I looked in the sample provided in the sdk and for their namespace they didn't use their package name but instead: "xmlns:Amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads"". So I am wondering what the correct namepace is that I should be using


Solution

  • I noticed on this quickstart guide it says that you should have the namespace as "xmlns:Amazon="http://schemas.android.com/apk/res/""

    I looked in the sample provided in the sdk and for their namespace they didn't use their package name but instead: "xmlns:Amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads""

    That first statement is not correct. In the quickstart guide it actually says that the namespace should be:

    xmlns:Amazon="http://schemas.android.com/apk/res/<type your package name>"
    

    Note the last part. That's important, because that's exactly the difference you're basing this question on.

    As with any custom view on Android, if you want to use one or more attributes that aren't covered by the Android namespace, you have to declare their location first. Normally, that means you copy the line above and append the package name of your project. The Amazon prefix can be pretty much anything you like, but it makes sense to give the namespace a name that is related to its definition.

    In this case, declaring the Amazon namespace, enables the usage of the Amazon:adSize attribute in the layout file. Without that declaration, your IDE will not know where to look for the adSize attribute.

    That being said, if you don't use any custom attributes, then there is no point in declaring the namespace, as you won't be using it. That's basically what IntelliJ is telling you. In other words: if you're not using Amazon:adSize in your layout, you can safely remove the Amazon namespace declaration.