본문 바로가기
IT라이프

android AdMob 추가하기

by zairan 2014. 4. 15.

1. 구글 애드몹 sdk 다운로드 해서 압축풀기

GoggleAdMobAdsSdkAndroid-6.4.x.x.jar   파일을 projects - MyApp - proj.android - libs 에 복사하기


2. 프로젝트의 Android build 환경을 3.2 이상으로 주기

에러나면 올 클린 - 올 빌드 - 이클립스 재시작


3. AndroidManifest.xml 권한 주기

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

      package="com.plusblog.adtest"

      android:versionCode="1"

      android:versionName="1.0">


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

    <uses-feature android:glEsVersion="0x00020000" />

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


    <application android:label="@string/app_name"

        android:icon="@drawable/icon">


        <activity android:name=".adtest"

                  android:label="@string/app_name"

                  android:screenOrientation="portrait"

                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

                  android:configChanges="orientation">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        

        <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

    </application>

    

    <supports-screens android:largeScreens="true"

                      android:smallScreens="true"

                      android:anyDensity="true"

                      android:normalScreens="true"/>

                         

    <uses-permission android:name="android.permission.INTERNET"/>

</manifest>



4. src 폴더의 java 파일 애드몹 나오게 코드 추가하기

package com.MyCompany.admob;


import org.cocos2dx.lib.Cocos2dxActivity;

import org.cocos2dx.lib.Cocos2dxGLSurfaceView;


import android.os.Bundle;

// admob Start

import com.google.ads.*;

import android.widget.*;

import android.view.Gravity;

// admob End


public class AdmobTest extends Cocos2dxActivity{

// admob Start

private static AdView adView;

private static Cocos2dxActivity me = null;

private final int WC = LinearLayout.LayoutParams.WRAP_CONTENT;

private final int MP = LinearLayout.LayoutParams.MATCH_PARENT;

// admob End

    protected void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

// admob Start

adView = new AdView(this, AdSize.SMART_BANNER, "ca-app-pub-번호");

FrameLayout.LayoutParams adParams = new FrameLayout.LayoutParams(WC, WC);

adParams.gravity = (Gravity.BOTTOM|Gravity.CENTER);

addContentView(adView, adParams);

adView.loadAd(new AdRequest());

me = this;

// admob End

}


    public Cocos2dxGLSurfaceView onCreateView() {

    Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);

    // AdmobTest should create stencil buffer

    glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);

   

    return glSurfaceView;

    }


    // admob Start

    protected void onDestroy()

    {

    if (adView != null)

    {

    adView.destroy();

    }

    super.onDestroy();

    }

  // admob End

    

    static {

        System.loadLibrary("cocos2dcpp");

    }     

}



반응형

댓글