First to Amazon's official website to download APP-SDK, after the decompression can be, but there are a lot of SDKs, we only use to import ads ADK on the line, this is simpler than Google, directly into the jar of the package on the line. Attach the download path to the Amazon SDK here:
1 https://developer.amazon.com/public/resources/development-tools/sdk
After unpacking the ADK, find the jar package, copy to the Android project's Libs directory, as shown in the Lib directory as follows:
Then we need to modify the Android code, in fact, the same as the usual modification of the list file, and then write the Java code on the line:
To add the required permissions:
1 <uses-permissionAndroid:name= "Android.permission.INTERNET" />2 <uses-permissionAndroid:name= "Android.permission.ACCESS_COARSE_LOCATION" />3 <uses-permissionAndroid:name= "Android.permission.ACCESS_FINE_LOCATION" />4 <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE" />5 <uses-permissionAndroid:name= "Android.permission.ACCESS_WIFI_STATE" />
declaring activity
1 < Activity 2 Android:name = "Com.amazon.device.ads.AdActivity" 3 android:configchanges= "keyboardhidden|orientation|screensize">4 </activity>
Then look at the implementation of the activity:
1 /**2 * Copyright 2013-2014 Amazon.com, Inc. or its affiliates. All rights Reserved.3 * Licensed under the Apache License, Version 2.0 (the "License").4 * You are not a use this file except in compliance with the License.5 * A copy of the License is located athttp://aws.amazon.com/apache2.0/6 * or in the ' license ' file accompanying this file.7 * This file was distributed on a "as is" BASIS, without warranties OR8 * CONDITIONS of any KIND, either express or implied.9 * See the License for the specific language governing permissions andTen * Limitations under the License. One */ A PackageCom.lemi.testamazon; - - Importcom.amazon.device.ads.*; the - Importandroid.app.Activity; - ImportAndroid.os.Bundle; - ImportAndroid.util.Log; + ImportAndroid.view.LayoutInflater; - ImportAndroid.view.View; + ImportAndroid.view.ViewGroup.LayoutParams; A at - Public classMainactivityextendsActivity { - Privateadlayout AdView; - - Private Static FinalString App_key = "Sample-app-v1_pub-2"; - Private Static FinalString Log_tag = "Lemi"; in - @Override to Public voidOnCreate (FinalBundle savedinstancestate) { + Super. OnCreate (savedinstancestate); -Adregistration.enablelogging (true); theLayoutinflater Inflater = (layoutinflater) This. Getsystemservice ( This. Layout_inflater_service); *View view = Inflater.inflate (R.layout.main,NULL); $ Panax Notoginseng This. AdView =(adlayout) View.findviewbyid (R.id.ad_view); - This. Adview.setlistener (NewSampleadlistener ()); the +Addcontentview (View,NewLayoutparams (layoutparams.fill_parent,layoutparams.fill_parent)); A the Try { + Adregistration.setappkey (app_key); -}Catch(FinalException e) { $LOG.E (Log_tag, "Exception thrown:" +e.tostring ()); $ return; - } - the Loadad (); - Wuyi } the - Wu Public voidLoadad () { - This. Adview.loadad (); About } $ - classSampleadlistenerextendsDefaultadlistener - { - A @Override + Public voidOnadloaded (FinalAd AD,Finaladproperties adproperties) { theLOG.I (Log_tag, Adproperties.getadtype (). toString () + "ad loaded successfully."); - } $ the @Override the Public voidOnadfailedtoload (FinalAd AD,Finaladerror Error) { theLOG.W (Log_tag, "Ad failed to load. Code: "+ error.getcode () +", Message: "+error.getmessage ()); the } - in @Override the Public voidOnadexpanded (FinalAD AD) { theLOG.I (Log_tag, "Ad expanded."); About the } the the @Override + Public voidOnadcollapsed (FinalAD AD) { -LOG.I (Log_tag, "Ad collapsed."); the Bayi } the } the}
Note that I am using the Amazon test interface here, if you are developing your own application, you still need to change the key value of their own application
1 Private Static Final String App_key = "Sample-app-v1_pub-2";
The previous one: