question

Fredko avatar image
Fredko asked

Amazon ad and phonegap android

Hi, I'm disovering amazon ad since 30 minutes I actually use these code for a phonegap app android =================================================== package com.aa.bbb; import org.apache.cordova.DroidGap; import android.os.Bundle; import android.widget.LinearLayout; import com.google.ads.*; public class MainActivity extends DroidGap { private static final String MY_AD_UNIT_ID = "12121212121"; private AdView adView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.loadUrl("file:///android_asset/www/index.html"); // Adding AdMob banner adView = new AdView(this, AdSize.SMART_BANNER, MY_AD_UNIT_ID); LinearLayout layout = super.root; layout.addView(adView); adView.loadAd(new AdRequest()); } @Override public void onDestroy() { // Destroy the AdView. if (adView != null) { adView.destroy(); } super.onDestroy(); } } =================================================== I try to translate to this code for amazon ad =================================================== package com.aa.bbb; import org.apache.cordova.DroidGap; import android.os.Bundle; import android.widget.LinearLayout; //import com.google.ads.*; import com.amazon.device.ads.*; import android.app.Activity; import android.util.Log; import android.view.View; import android.widget.Button; public class MainActivity extends DroidGap { // private static final String MY_AD_UNIT_ID = "121212121"; private AdLayout adView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.loadUrl("file:///android_asset/www/index.html"); AdRegistration.setAppKey("0123456789ABCDEF0123456789ABCDEF"); // Programmatically create the AmazonAdLayout this.adView = new AdLayout(this); LinearLayout layout = (LinearLayout) findViewById(R.id.ad_view); // Set the correct width and height of the ad. LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); layout.addView(this.adView,lp); // If you declared AdLayout in your xml you would instead // replace the 3 lines above with the following line // this.adView = (AdLayout) findViewById( R.id.adview ); this.adView.loadAd(new AdTargetingOptions()); // async task to retrieve an ad } @Override public void onDestroy() { // Destroy the AdView. if (adView != null) { adView.destroy(); } super.onDestroy(); } } =================================================== But I have an error on the follow line : LinearLayout layout = (LinearLayout) findViewById(R.id.ad_view); 1) Can I use admob mediation for amazon ads ? 2) Can you help to find a code wish work with a phonegap application ? Cdly, Frédéric Message was edited by: Fredko
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 Fredko, Thank you for posting. Which error you are getting? Is it a run time error? Here is the link you should refer for information on Mediator SDK Integration with Amazon ads. https://developer.amazon.com/sdk/mobileads/with-other-sdks.html#Mediator%20SDK%20Integration We are unable to provide working phonegap code sample with amazon ads. I would post back when I would have it.
10 |5000

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

Fredko avatar image
Fredko answered
1) Amazon ads code seem not to be compatible with phonegap app. Does Amazon try it ? Have you a code which work with cordova ? 2) Actually I use AdMob so I ask if I can use API Admob and Amazon ads by mediation. I don't understand the link you give me, english is not my native language. 3) Since 2 months we said me publish an app on Amazon is not free (arround 99 $ per year), In fact I publish an app gratis and Amazon never ask me money... WTF ?
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 Fredko, I am going to give it a try with PhoneGap. I will post back the result. Thanks for reporting the issue.
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 Fredco, I am successfully able to integrate Amazon Ads sdk in an PhoneGap app. Below is the code. Ad is appearing over the phonegap's webview. Hope it helps. package com.example.hello; import android.os.Bundle; import android.util.Log; import android.view.ViewGroup; import android.widget.LinearLayout; import com.amazon.device.ads.*; import org.apache.cordova.Config; import org.apache.cordova.DroidGap; public class HelloWorld extends DroidGap implements AdListener { private static final String APP_KEY = "sample-app-v1_pub-2"; // Sample Application Key. Replace this variable with your Application Key private static final String LOG_TAG = "SimpleAdSample"; // Tag used to prefix all log messages private AdLayout adView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set by in config.xml super.loadUrl(Config.getStartUrl()); //super.loadUrl("file:///android_asset/www/index.html") LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); ((ViewGroup) appView.getParent()).removeView(appView); adView = new AdLayout(this,AdSize.SIZE_300x50); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); adView.setLayoutParams(lp); linearLayout.addView(adView); AdRegistration.enableLogging(true); AdRegistration.enableTesting(true); adView.setListener(this); try { AdRegistration.setAppKey(APP_KEY); } catch (Exception e) { Log.e(LOG_TAG, "Exception thrown: " + e.toString()); return; } linearLayout.addView(appView); setContentView(linearLayout); LoadAd(); } public void LoadAd() { // Load the ad with the appropriate ad targeting options. AdTargetingOptions adOptions = new AdTargetingOptions(); adView.loadAd(adOptions); } /** * This event is called after a rich media ads has collapsed from an expanded state. */ @Override public void onAdCollapsed(AdLayout view) { Log.d(LOG_TAG, "Ad collapsed."); } /** * This event is called if an ad fails to load. */ @Override public void onAdFailedToLoad(AdLayout view, AdError error) { Log.w(LOG_TAG, "Ad failed to load. Code: " + error.getCode() + ", Message: " + error.getMessage()); } /** * This event is called once an ad loads successfully. */ @Override public void onAdLoaded(AdLayout view, AdProperties adProperties) { Log.d(LOG_TAG, adProperties.getAdType().toString() + " Ad loaded successfully."); } /** * This event is called after a rich media ad expands. */ @Override public void onAdExpanded(AdLayout view) { Log.d(LOG_TAG, "Ad expanded."); } } ------------------------ Manifest: -------------------------
10 |5000

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

Fredko avatar image
Fredko answered
Thx I will test this code soon
10 |5000

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