Test_Target Android SDK by bestt571

VIEWS: 18 PAGES: 2

More Info
									                                                                  Test&Target	
  Android	
  SDK	
  
	
  
Introduction	
  
Adobe	
  provides	
  the	
  ability	
  to	
  deliver	
  targeted	
  content	
  and	
  track	
  user	
  actions	
  within	
  Android	
  applications	
  
through	
  the	
  Test&Target	
  Android	
  SDK,	
  which	
  is	
  a	
  Java	
  library	
  provided	
  in	
  the	
  form	
  of	
  a	
  JAR	
  file.	
  	
  The	
  
content	
  returned	
  from	
  Test&Target	
  can	
  be	
  any	
  text-­‐based	
  content	
  such	
  as	
  HTML,	
  XML	
  or	
  plain	
  text.	
  	
  Once	
  
the	
  content	
  is	
  loaded,	
  it	
  is	
  then	
  up	
  to	
  the	
  Android	
  application	
  developer	
  to	
  decide	
  how	
  the	
  content	
  is	
  
consumed	
  within	
  the	
  application.	
  	
  The	
  content	
  can	
  be	
  displayed	
  as	
  HTML,	
  or	
  used	
  to	
  change	
  the	
  behavior	
  
of	
  the	
  application.	
  	
  This	
  guide	
  provides	
  a	
  simple	
  use	
  example	
  of	
  the	
  Test&Target	
  Android	
  SDK.	
  

Requirements	
  
The	
  Test&Target	
  Android	
  SDK	
  is	
  compatible	
  with	
  all	
  current	
  Android	
  Platforms	
  including	
  the	
  Android	
  2.1	
  
Platform	
  (the	
  latest	
  version	
  as	
  of	
  this	
  writing	
  is	
  2.1	
  revision	
  1).	
  	
  Below	
  is	
  the	
  list	
  of	
  software	
  required	
  for	
  
building	
  the	
  example	
  application:	
  

       1. JDK	
  5	
  or	
  JDK	
  6	
  
       2. Eclipse	
  IDE	
  for	
  Java	
  Developers	
  version	
  3.4	
  (Ganymede)	
  or	
  3.5	
  (Galileo)	
  	
  
       3. Android	
  SDK	
  
       4. Android	
  Development	
  Tools	
  (ADT)	
  Plugin	
  for	
  Eclipse	
  
       5. Android	
  1.5	
  Platform	
  or	
  later	
  

Code	
  Example	
  
Here	
  we	
  cover	
  a	
  basic	
  example	
  of	
  how	
  to	
  load	
  HTML	
  content	
  from	
  Test&Target	
  into	
  a	
  WebView	
  within	
  a	
  
simple	
  Android	
  application.	
  	
  This	
  example	
  assumes	
  that	
  the	
  associated	
  HTML	
  Offers	
  and	
  campaign	
  have	
  
already	
  been	
  created	
  in	
  the	
  Test&Target	
  Admin	
  Tool,	
  and	
  that	
  the	
  campaign	
  has	
  been	
  approved.	
  

1. Log	
  into	
  the	
  Test&Target	
  Admin	
  tool	
  and	
  download	
  the	
  Test&Target	
  Android	
  SDK	
  from	
  the	
  Mobile	
  
       tab.	
  	
  The	
  ZIP	
  file	
  contains	
  the	
  JAR	
  file	
  as	
  well	
  as	
  the	
  Javadoc-­‐generated	
  API.	
  To	
  view	
  the	
  API,	
  open	
  the	
  
       TnT_Android_SDK_API/index.html	
  file	
  in	
  a	
  browser.	
  
   	
  
2. Create	
  a	
  folder	
  called	
  “lib”	
  in	
  your	
  Android	
  Project,	
  and	
  drag	
  the	
  TnT_Android_SDK.jar	
  file	
  into	
  this	
  
       folder.	
  	
  Right-­‐click	
  the	
  JAR	
  file,	
  and	
  select	
  Build	
  Path	
  -­‐>	
  Add	
  to	
  Build	
  Path.	
  	
  In	
  your	
  project	
  properties,	
  
       select	
  Java	
  Build	
  Path,	
  and	
  make	
  sure	
  the	
  JAR	
  file	
  is	
  checked	
  under	
  Order	
  and	
  Export.	
  
	
  
3. Import	
  the	
  package	
  at	
  the	
  top	
  of	
  your	
  Application	
  or	
  Activity	
  subclass.	
  
       import com.adobe.testandtarget.mobile.android.*;
4. Follow	
  the	
  numbered	
  code	
  below	
  for	
  creating	
  an	
  mbox	
  (see	
  comments	
  for	
  explanation	
  of	
  each	
  line	
  of	
  
   code).	
  	
  To	
  complete	
  this	
  step,	
  you	
  will	
  need	
  to	
  know	
  your	
  client	
  code	
  and	
  the	
  name	
  of	
  the	
  mbox	
  used	
  
   in	
  the	
  campaign	
  setup	
  in	
  the	
  Test&Target	
  Admin	
  Tool.	
  
          public class AndroidDemoApplication extends Activity {
            private WebView _webView;

            public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              _webView = new WebView(this);
              setContentView(_webView);

              // 1. Create an instance of the MboxFactory class with your client code.
              MboxFactory factory = new MboxFactory("androiddemo16");

              // 2. Use the MboxFactory instance to create an Mbox.
              Mbox mbox = factory.create("DemoApp");

              // 3. Set the default content for the Mbox.
              mbox.setDefaultContent("<h1>DEFAULT CONTENT</h1>");

              /**
               * 4. Create a custom MboxContentConsumer to consume the content returned. The
               *    CustomMboxContentConsumer class defined below simply displays the content
               *    returned in a BrowserField as HTML.
               */
              CustomConsumer consumer = new CustomConsumer(_webView);
              mbox.addOnLoadConsumer(consumer);

              // 5. Load the Mbox.
              mbox.load();

              ...

5. Define	
  the	
  custom	
  class	
  that	
  implements	
  the	
  MboxContentConsumer	
  interface.	
  	
  This	
  abstract	
  interface	
  
   only	
  requires	
  that	
  you	
  define	
  a	
  method	
  named	
  “consume”	
  to	
  pass	
  content	
  into.	
  	
  The	
  CustomConsumer	
  
   class	
  defined	
  below	
  simply	
  displays	
  the	
  content	
  in	
  a	
  WebView.	
  

           class CustomConsumer implements MboxContentConsumer {
             private WebView _view;
             public CustomConsumer(WebView webview) {
               _view = webview;
             }
             public void consume(String content) {
               _view.loadData(content, "text/html", "utf-8");
             }
           }
   	
  
6. In	
  your	
  AndroidManifest.xml,	
  make	
  sure	
  you	
  have	
  added	
  the	
  user	
  permission	
  for	
  accessing	
  the	
  
   internet.	
  	
  The	
  corresponding	
  line	
  for	
  this	
  permission	
  should	
  be	
  similar	
  to	
  this:	
  
   	
  
          <uses-permission android:name="android.permission.INTERNET"></uses-permission>
   	
  
7. Right-­‐click	
  your	
  project,	
  and	
  go	
  to	
  Run	
  As	
  -­‐>	
  Android	
  Application	
  to	
  build	
  and	
  test	
  your	
  application.	
  	
  If	
  
   you	
  have	
  correctly	
  setup	
  and	
  approved	
  your	
  Test&Target	
  campaign,	
  you	
  should	
  see	
  your	
  offer	
  
   displayed	
  in	
  the	
  Android	
  device	
  emulator.	
  

								
To top