显示广告在AndEngine [英] Displaying Ad In AndEngine

查看:116
本文介绍了显示广告在AndEngine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示AndEngine使用Greystrip广告。

我无法弄清楚如何做到这一点,因为它不使用布局膨胀的意见,但尚未精灵。

我使用BaseGameActivity创建为每个场景我想显示加上我的应用程序。

在GreyStrip这也是他们告诉你在你的应用程序中集成广告。

  

在您的应用程序GSSDK加入呼叫,您需要   纳入SDK到您的Andr​​oidManifest.xml。添加以下   在节,取代   与包标识符是唯一的应用程序。本   内容提供者管理的广告内容本地存储,而   活动管理广告展示。

 <提供机器人:名称=com.greystripe.android.sdk.AdContentProvider
    机器人:当局=< YOUR_APPLICATION_PACKAGE> .AdContentProvider
机器人:多进程=真
机器人:出口=FALSE/>
<活动机器人:名称=com.greystripe.android.sdk.AdView
机器人:configChanges =键盘| keyboardHidden |定位>
<意向滤光器>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
 

  

要初始化的Greystripe SDK,调用初始化方法在   启动。这应该您的应用程序的onCreate中完成()   方法。此调用将产生一个后台线程来初始化我们   活动,然后将控制返回到您的应用程序。在这个背景下,   的Greystripe活动将下载的广告以及任何SDK更新。   参数:CTX:您的应用程序上下文实例APPID:使用   应用程序在注册过程中的appid提供。提供了一个无效的appid   将导致SDK显示错误通知广告。

 公共静态GSSDK初始化(上下文CTX,字符串的appid)
 

  

要使用的一面旗帜,放置在你的main.xml中的文件如下:

 <视图类=com.greystripe.android.sdk.BannerView
机器人:ID =@ + ID / gsBanner
机器人:layout_width =320dp
机器人:layout_height =48dp/>
 

  

要引用code大旗认为,使用findViewById,与任何   main.xml中的元素:

  BannerView myBanner =(BannerView)findViewById(R.id.gsBanner);
 

要申请增加了通话

  myBanner.refresh();
 

现在的问题是,因为我没有一个XML布局我无法弄清楚如何膨胀的布局广告的看法?

任何人有什么想法?

编辑:

我见过有人做这样的教程在网上,但我怎么能吹这andengine?

 尝试{
    串的applicationID = Utils.scrapeIgnoreCase(externalParams,&所述; PARAM NAME = \标识\>中,&所述; /参数>中);
    GSSDK.initialize(背景下,的applicationID);

    BannerView myBanner =新BannerView(上下文);
    myBanner.setLayoutParams(view.getLayoutParams());
    myBanner.addListener(新GreyStripeBannerListener());
    view.addView(myBanner);
    myBanner.refresh();
    myBanner.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            点击();
        }
    });
 

解决方案

我使用AdMob的,但它应该是相似的。

像@Sergey贝内引用,你必须重写 onSetContentView 在您的活动,然后创建 RenderSurfaceView 和你手动广告视图。

首先,创建一个的FrameLayout 包含AndEngine的观点和广告视图。 添加AndEngine的观点,并创建自己的广告图,然后设置框架布局的内容视图。

  @覆盖
保护无效onSetContentView(){
    //创建父框架布局:
    最后的FrameLayout的FrameLayout =新的FrameLayout(本);
    //创建它的布局参数,可以使其充满屏幕。
    最后FrameLayout.LayoutParams frameLayoutLayoutParams =
            新FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
                    FrameLayout.LayoutParams.FILL_PARENT);

    //创建横幅视图。
    BannerView bannerView =新BannerView(本);

    // ....
    //是否有任何initiallizations在这里的旗帜看法。
    // ....

    //创建横幅布局PARAMS。与此PARAMS,广告将被放置在屏幕的顶部,中间水平。
    最后FrameLayout.LayoutParams bannerViewLayoutParams =
            新FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT,
                    Gravity.TOP | Gravity.CENTER_HORIZONTAL);

    //创建AndEngine的观点。
    this.mRenderSurfaceView =新RenderSurfaceView(本);
    mRenderSurfaceView.setRenderer(mEngine,这一点);

    // createSurfaceViewLayoutParams是AndEngine方法创建PARAMS其观点。
    最后android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
            新FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());

    //添加到框架布局的意见。
    frameLayout.addView(this.mRenderSurfaceView,surfaceViewLayoutParams);
    frameLayout.addView(bannerView,bannerViewLayoutParams);

    //设置内容视图
    this.setContentView(的FrameLayout,frameLayoutLayoutParams);
}
 

将这种方法在你的 BaseGameActivity 类。

I am trying to display an advertisement using Greystrip in AndEngine.

I cannot figure out how this is done because it doesnt use a Layout to inflate views, but yet sprites.

i use BaseGameActivity to create my application for each scene i would like to display adds on.

In GreyStrip this is how they tell you to integrate ads in your application..

Before adding calls in your application to GSSDK, you need to incorporate the SDK into your AndroidManifest.xml. Add the following in the section, replacing with a package identifier that is unique to your application. This Content Provider manages local storage of ad content, while the Activity manages ad display.

 <provider android:name="com.greystripe.android.sdk.AdContentProvider"
    android:authorities="<YOUR_APPLICATION_PACKAGE>.AdContentProvider"
android:multiprocess="true"
android:exported="false" />
<activity android:name="com.greystripe.android.sdk.AdView"
android:configChanges="keyboard|keyboardHidden|orientation" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

To initialize the Greystripe SDK, call the initialize method at startup. This should be done within your application’s onCreate() method. This call will spawn a background thread to initialize our activity, and then return control to your app. In this background, the Greystripe activity will download ads as well as any SDK updates. Parameters: ctx: Your application Context instance appId: Use the appId provided during app registration. Providing an invalid appId will cause the SDK to display error notification ads.

 public static GSSDK initialize(Context ctx, String appId)

To use a banner, place the following in your main.xml file:

<view class="com.greystripe.android.sdk.BannerView"
android:id="@+id/gsBanner"
android:layout_width="320dp"
android:layout_height="48dp"/>

To reference the banner view in code, use findViewById, as with any main.xml element:

BannerView myBanner = (BannerView) findViewById(R.id.gsBanner);

To request adds call

myBanner.refresh();

Now the problem is since i dont have an xml layout i cant figure out how i inflate the layout for the ad view?

Anyone have any ideas?

EDIT:

Ive seen someone do it like this in a tutorial online, but how can i inflate this in andengine?

try {
    String applicationId = Utils.scrapeIgnoreCase(externalParams, "<param name=\"id\">", "</param>");           
    GSSDK.initialize(context, applicationId);

    BannerView myBanner = new BannerView(context);          
    myBanner.setLayoutParams(view.getLayoutParams());
    myBanner.addListener(new GreyStripeBannerListener());           
    view.addView(myBanner);
    myBanner.refresh();
    myBanner.setOnClickListener(new  View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Click();
        }
    });

解决方案

I'm using AdMob but it should be similar.

Like @Sergey Benner referenced, you have to override onSetContentView in your activity, then create the RenderSurfaceView and your ad view manually.

First of all, create a FrameLayout to contain AndEngine's view and the ad view. Add AndEngine's view and create your ad view, then set the frame layout as the content view.

@Override
protected void onSetContentView() {
    //Creating the parent frame layout:
    final FrameLayout frameLayout = new FrameLayout(this);
    //Creating its layout params, making it fill the screen.
    final FrameLayout.LayoutParams frameLayoutLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
                    FrameLayout.LayoutParams.FILL_PARENT);

    //Creating the banner view.
    BannerView bannerView = new BannerView(this);

    //....
    //Do any initiallizations on the banner view here.
    //....

    //Creating the banner layout params. With this params, the ad will be placed in the top of the screen, middle horizontally.
    final FrameLayout.LayoutParams bannerViewLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT,
                    Gravity.TOP | Gravity.CENTER_HORIZONTAL);

    //Creating AndEngine's view.
    this.mRenderSurfaceView = new RenderSurfaceView(this);
    mRenderSurfaceView.setRenderer(mEngine, this);

    //createSurfaceViewLayoutParams is an AndEngine method for creating the params for its view.
    final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
            new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());

    //Adding the views to the frame layout.
    frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
    frameLayout.addView(bannerView, bannerViewLayoutParams);

    //Setting content view
    this.setContentView(frameLayout, frameLayoutLayoutParams);
}

Place this method in your BaseGameActivity class.

这篇关于显示广告在AndEngine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆