1 请在 http://www.samsungadhub.com 注册帐户
2 http://developer.bada.com --> MyApplications 注册一个新的application profile,需要加入AD_SERVER,SYSTEM_SERVER,下载manifest.xml,覆盖项目根目录的同名文件
3 添加一个AdListener类
#ifndef __ADLISTENER_H__
#define __ADLISTENER_H__
#include <FAds.h>
class AdListener : public Osp::Ads::Controls::IAdListener
{
public:
AdListener();
virtual ~AdListener();
result Create();
void RefreshAd(void);
void OnAdReceived(RequestId reqId, const Osp::Ads::Controls::Ad& source, result r, const Osp::Base::String& errorCode, const Osp::Base::String& errorMsg);
public:
Osp::Ads::Controls::Ad* __pAd;
};
#endif /* ADLISTENER_H_ */
#include "AdListener.h"
using namespace Osp::Ads::Controls;
using namespace Osp::Base;
using namespace Osp::Base::Collection;
using namespace Osp::Ui::Controls;
AdListener::AdListener():__pAd(NULL) {
// TODO Auto-generated constructor stub
}
AdListener::~AdListener() {
// TODO Auto-generated destructor stub
}
result AdListener::Create()
{
result r = E_SUCCESS;
__pAd = new Ad();
if ( __pAd == NULL )
{
AppLog("Ad malloc failed.");
return -1;
}
r = __pAd->Construct(Osp::Graphics::Rectangle(0, 0, 480, 80), L"2011000001_001", this);
if (IsFailed(r))
{
AppLog("[%s] Ad construction failed.", GetErrorMessage(r));
return r;
}
//__pAd->SetTextColor(Osp::Graphics::Color(255, 255, 255));
//__pAd->SetBackgroundColor(Osp::Graphics::Color(0, 0, 0));
// Set keywords
ArrayList* pKeywordsList = new ArrayList;
pKeywordsList->Construct();
pKeywordsList->Add(*(new String(L"bada")));
pKeywordsList->Add(*(new String(L"Samsung")));
__pAd->SetKeywords(pKeywordsList);
delete pKeywordsList;
// Set the extra information
HashMap* pExtraInfoList = new HashMap;
pExtraInfoList->Construct();
pExtraInfoList->Add(*(new String(L"gender")), *(new String(L"male")));
pExtraInfoList->Add(*(new String(L"age")), *(new String(L"30")));
pExtraInfoList->Add(*(new String(L"interests")), *(new String(L"car,soccer")));
pExtraInfoList->Add(*(new String(L"location")), *(new String(L"37.5,127.5,10.5")));
__pAd->SetExtraInfo(pExtraInfoList);
delete pExtraInfoList;
return r;
}
void AdListener::RefreshAd(void)
{
RequestId reqId;
__pAd->RequestAd(reqId);
}
void AdListener::OnAdReceived(RequestId reqId, const Osp::Ads::Controls::Ad& source, result r, const Osp::Base::String& errorCode, const Osp::Base::String& errorMsg)
{
AppLog("[Received Ad] (reqId=%d, r=%s, errorCode=%S, errorMsg=%S)", reqId, GetErrorMessage(r), errorCode.GetPointer(), errorMsg.GetPointer());
// Do something
}
此处需要修改construct的inventy id,其应该是自己申请的id
4:修改AppDelegate.cpp
4.1 文件头添加include文件
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
#include "AdListener.h"
AdListener* g_pAdListener = NULL;
#endif
4.2 AppDelegate::initInstance()
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
g_pAdListener = new AdListener();
g_pAdListener->Create();
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 800, 480));
//pMainWnd->setDeviceOrientation(Osp::Ui::ORIENTATION_LANDSCAPE);
CCFileUtils::setResourcePath("/Res/");
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif // CC_PLATFORM_BADA
此处需要注意:
(1):对AdListener的Create必须放在对CCEGLView之前。我放在之后,app会crash
同时此处也不能将Ad实例添加到pMainWnd中,否则也会crash
这两个问题没深入分析原因
(2):我为了实现横屏下广告条竖立效果,故将pMainWnd->setDeviceOrientation(Osp::Ui::ORIENTATION_LANDSCAPE);用CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); 代替
4.3 AppDelegate::applicationDidFinishLaunching()
函数末尾添加:
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
CCEGLView& glview = CCEGLView::sharedOpenGLView();
glview.AddControl(*(g_pAdListener->__pAd));
g_pAdListener->RefreshAd();
#endif
(以上就可显示了)