让 AdView 工作

Getting AdView to work(让 AdView 工作)

本文介绍了让 AdView 工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 libgdx 中开发游戏.我阅读了官方文档并尝试将 MobClix 广告集成到我的应用程序中,但 eclipse 无法解析 ADView 类的此构造函数:(例如):

I am developing a game in libgdx. I read the official docs and tried to integrate MobClix Ads in my App but eclipse can't resolve this constructor for ADView class: (for Example):

 AdView ad = new AdView(this, AdSize.BANNER, "a14d91b10f12454");

这行代码给我一个错误.

This line of code give me an error.

也许我的导入不正确?我导入这个:

Maybe my import is not correct? I import this:

import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

同样的:

 adView.loadAd(new AdRequest());

我试图寻找答案,但我找不到,有人知道如何解决这个问题吗?

I tried to search for an answer but I coudn't find, Does somone know how to resolve this?

对不起,我的英语不好.

Sorry for my poor english.

推荐答案

把这段代码放到mainactivity中

import android.app.Activity;
import android.os.Bundle;

import com.startapp.android.publish.StartAppAd;

public class MainActivity extends Activity {


    private StartAppAd add = new StartAppAd(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        StartAppAd.init(this, "105158220", "205151606");
    //StartAppSearch.init(this, "105158220", "205151606");
        setContentView(R.layout.activity_main);

    if(add.isReady())
    {
        add.showAd(); // show the ad
        add.loadAd();
    }   
        //a.loadAd(AdMode.FULLPAGE);

    }
    @Override
    public void onResume(){
    super.onResume();
    add.onResume();
    }

    @Override
    public void onBackPressed() {
    add.onBackPressed();
    super.onBackPressed();
    }

    @Override
    public void onPause() {
    super.onPause();
    add.onPause();
    } 

}

把它放到你的xml文件中

put this into your xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


<com.startapp.android.publish.banner.banner3d.Banner3D
android:id="@+id/startApp3DBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>

把它放到你的 Manifest 文件中

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.GET_TASKS" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.start_up_app.MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation"
            android:label="@string/app_name"
             >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.startapp.android.publish.list3d.List3DActivity"
            android:taskAffinity="com.example.start_up_app.AppWall"
            android:theme="@android:style/Theme" />
        <activity
            android:name="com.startapp.android.publish.AppWallActivity"
            android:configChanges="orientation|keyboardHidden"
            android:taskAffinity="com.example.start_up_app.AppWall"
            android:theme="@android:style/Theme.Translucent" />
    </application>

</manifest>

因为你必须使用 StartAppCommon-1.0.1.jar 和 StartAppInApp-2.0.7.jar

这篇关于让 AdView 工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:让 AdView 工作

基础教程推荐