Tuesday, January 11, 2011

Ads Service in Blackberry

Hello

Working with Ads Service in Blackberry is really great and new experience for those who haven't worked on iAds in iPhone.
I have gathered some information that i would like to share with all and may be some where somebody can be helped by it.

Advertisements rule the world...Keeping this in mind Blackberry platform provides you the capability to display ads in your Blackberry Device Application. Many of you must have seen such feature in iPhone Apps where ads are called as iAds.

To sign up for the Advertising Service, visit adservice.blackberry.com/register/




Using the Advertising Service SDK:

1) For each application that you integrate ads into, you need a unique instance of the Advertising Service SDK.

2) If you have multiple applications in which you want to display ads, you must register each application with Research In Motion separately.

3) Each application that you register, RIM sends you a new SDK which is identified by a unique package ID.

4) To use the Advertising Service API in an application, you have to add the .jar file for the Advertising Service API to the build path of a BlackBerry application project,after this develop and package the application, and distribute the application .cod file with the .cod file that contains the Advertising Service API.

System requirements

• BlackBerry® Java® Plug-in for Eclipse® 1.1 or later with the BlackBerry Java SDK 4.5 - 5.0.
"The Advertising Service does not yet fully support BlackBerry® Device Software 6.0."

• BlackBerry® Java® Development Environment 4.5 or later

• BlackBerry® Email and MDS Services Simulator Package 4.1.2 or later


How to move ahead:

1) RIM send you two zipped files that you need to unzip

BlackBerrySDK_app<package_ID>._Desktop

BlackBerrySDK_app<package_ID>._OTA

2) When you unzip them you can find many folders that contains the alx, cod, jad, jar files for different versions.

Files contained:
net_rim_bbapi_adv_<package_ID>.alx

net_rim_bbapi_adv_<package_ID>.cod

net_rim_bbapi_adv_<package_ID>.jad

net_rim_bbapi_adv_<package_ID>.jar


3) To add the .jar file of the Advertising Service API to your BlackBerry application Project :

Create a BlackBerry application project:

1. In Eclipse, in the Package/Project Explorer view, right-click the project that you want to add the .jar file to.
2. Click Build Path > Configure Build Path.
3. Click the Libraries tab.
4. Click Add External JARS if the .jar file is not in the current workspace (Prefer to add the jar file of particular version in your src folder).
5. Double-click net_rim_bbapi_adv_<package_ID>.jar to add the .jar file to the project.
7. Click OK.

Note: This itself doesn’t completes the task, you must also load the .cod file for the Advertising Service API on a BlackBerry device or in the BlackBerry Smartphone Simulator before an application can run.It would be a better option if you place the cod file in the simulators directory.

Ads Display Size
The Advertising Service supports the following sizes of ads, in pixels:
• 320 x 53 (required size for rich media ads)
• 216 x 36
• 168 x 28
• 120 x 20

Namespace:

import net.rim.blackberry.api.advertising.<package_ID>.Banner;

Here you go

package com.Test;

import net.rim.blackberry.api.advertising.appXXXXX.Banner;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.UiApplication;
class Ads extends UiApplication
{
    public static void main(String[] args)
     { 
       Ads theApp = new Ads();
       theApp.enterEventDispatcher();
     }
    public Ads()
     {
        pushScreen(new AdDemoScreen());
     }

 class AdDemoScreen extends MainScreen
   {
      public AdDemoScreen()
       {
          Banner bannerAd = new Banner(placementId, null);
          bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
         add(bannerAd);
       }
   }
 }

How to send Meta data with Ads:

import net.rim.blackberry.api.advertising.<package_ID>.Banner;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.UiApplication;
import java.util.Hashtable;

  public class Ads extends UiApplication
   {
      public static void main(String[] args)
       {
         Ads theApp = new AdDemo();
         theApp.enterEventDispatcher();
       }
    public Ads()
    {
       pushScreen(new AdsScreen());
     }
  }
 class AdsScreen extends MainScreen
  {
     public AdsScreen()
     {
        Hashtable metadata = new Hashtable();
        metadata.put("age", "61");
        metadata.put("gender", "female");

        Banner bannerAd = new Banner(placement_Id, metadata);
        bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
        add(bannerAd);
     }
 }

package_ID : (appXXXXX) You can see this number on the files that RIM send you.(net_rim_bbapi_adv_appXXXXX.jar).

placement_Id : When RIM sends you the files they also send some credentials containing placement_id

Package a BlackBerry application project
1. In Package Explorer view, right-click a BlackBerry project.
2. Click BlackBerry > Package Project(s).
The Console view displays the progress of packaging.


Run an application that displays ads on a device
1. Connect a BlackBerry device to a computer with a USB cable.
2. Oopen Command prompt.
3. At the command prompt, type cd <location_of_application_deliverable_files> and press Enter.
4. At the command prompt, type javaloader -u load <my_jad_file.jad> and press Enter to load the .jad file for the application on the BlackBerry device.
6. On the Home screen of the device, navigate to and click the application icon.

Customizing the appearance and behavior of the display area for an ad

1) setMMASize() : Sets the size of the Banner object.

1) If your application runs on a BlackBerry Device Software version earlier
than 5.0 so use setMMASize().

2) If your application runs on BlackBerry Device Software 5.0, and you do not set the size in the application code, the Banner object resizes itself automatically to match the size of the ad that the mediation layer returns.

If you set a size that is different from the one that you specify when you register your application, the server-side value overrides the size that you set in the application, potentially causing ads to display incorrectly.


bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
Other Options for size:

Banner.MMA_SIZE_EXTRA_SMALL

Banner.MMA_SIZE_EXTRA_MEDIUM

Banner.MMA_SIZE_EXTRA_LARGE

Banner.MMA_SIZE_EXTRA_AUTO


2) Transition effect - The application by default displays a black transition effect between 2 ads.You can call this as fade in and fade out.

bannerAd.enableBannerTransition(false) – To turn off the transition effect
bannerAd. setBannerTransitionColor(Color.RED) - To specify a transition color that is supported by the Color class in the BlackBerry® Java® SDK.


3) Focus behavior- The application by default displays a blue border around the ad By default, when a user selects an ad.

bannerAd setBorderColor(Color.BLACK) - To specify a focus color that is supported by the Color class in the BlackBerry® Java® SDK.

bannerAd.setFocusOverrideFlag(true) – To prevent the Advertising Service API from handling focus behavior.


4) Placeholder image - Tthe application by default displays a transparent placeholder image with a border when ad service is waiting for an ad. You can customize the placeholder image, you can create a Bitmap object and pass it to the constructor for a Banner object as a parameter.

If you create your own placeholder image, verify that it has the same dimensions as the ads that
your application receives.

Bitmap customPlaceholder = Bitmap.getBitmapResource("Ad_placeholder.png");

Banner bannerAd = new Banner(placementId, null, 100000, customPlaceholder);

Enjoy Coding!!!!!!!!!!!

:)

8 comments:

  1. how to add click event in banner ?

    ReplyDelete
  2. You can try navigationClick.
    if focus is on the Banner , you can redirect the user to any link or do whatever u wanna do.

    ReplyDelete
  3. public class DemonstrationScreen extends MainScreen {
    public DemonstrationScreen()
    {
    final Bitmap customPlaceholder = Bitmap.getBitmapResource("arrow.png");




    Banner bannerAd = new Banner(add.APID,null,10000, customPlaceholder);
    bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
    // bannerAd.setFocusOverrideFlag(true);
    VerticalFieldManager vfm = new VerticalFieldManager
    (VerticalFieldManager.NO_VERTICAL_SCROLL
    | VerticalFieldManager.NO_VERTICAL_SCROLLBAR
    | VerticalFieldManager.USE_ALL_WIDTH);
    HorizontalFieldManager hfm = new HorizontalFieldManager
    (HorizontalFieldManager.FIELD_HCENTER
    | HorizontalFieldManager.FIELD_VCENTER);
    hfm.add(bannerAd);
    vfm.add(hfm);
    add(vfm);

    }
    }

    this is my code. how i add the click event ? give me the code ?

    ReplyDelete
  4. use like this:

    baner.setfocus();

    protected boolean navigationClick(int status, int time)
    {
    if(bannerAd.isFocus())
    {
    //handle click event here
    }
    }

    ReplyDelete
  5. how would i get payment after implementing all these things ?

    ReplyDelete