Showing posts with label Ads. Show all posts
Showing posts with label Ads. Show all posts

Saturday, 10 November 2012

How to Place ads on Blackberry Application

If you have any requirement to place adverstisements like Banner Ads,Text adds etc...on to your Blackberry Application.Have a look at Below Code:

If you want to know more Information regarding Placing adds.Please have a look at BlackBerry Documents Click Here

Package Structure:


Step-1:Create a Project with any Name(Here I have Created with the name AddsonBlackBerry)
Step-2:Create a Class with the name AdDemo
Step-3: Place your Add Image under res/img Folder.

Finally Code Your AdDemo Class:

import java.util.Hashtable;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.UiApplication;
import net.rimlib.blackberry.api.advertising.app.Banner;
public class AdDemo extends UiApplication {
public static void main(String[] args) {
AdDemo theApp = new AdDemo();
theApp.enterEventDispatcher();
}
public AdDemo() {
pushScreen(new AdDemoScreen());
}
   }
 class AdDemoScreen extends MainScreen {
final Banner bannerAd;
public AdDemoScreen() {
Bitmap bit = Bitmap.getBitmapResource("BannerAd.png");
bannerAd = new Banner(85983, null,60000 , bit); bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_EXTRA_LARGE);
VerticalFieldManager vfm = new VerticalFieldManager( Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR
| Field.USE_ALL_WIDTH);
HorizontalFieldManager hfm = new HorizontalFieldManager(
Field.FIELD_HCENTER | Field.FIELD_VCENTER);
hfm.add(bannerAd);
vfm.add(hfm);
add(vfm);
bannerAd.setFocus();
} 
protected boolean navigationClick(int status, int time) {
if (bannerAd.isFocus()) {
Dialog.alert("Hellloooo");
}
return true;
}
}
Note: If you click on your Banner add and you want to perform some action,you can place the below logic:
protected boolean navigationClick(int status, int time) {
if (bannerAd.isFocus()) {
Dialog.alert("Hellloooo");
}
return true;
}

OutPut: