13 Sep

Integrasi AdMob dengan AndEngine

Step 1. Masukkan SDK AdMob ke dalam Project
Copy sdk file to lib folder inside your project, then right-click on the file build path -> add to build path.

Step 2. Edit AndroidManifest.xml

masukkan permissions ke manifest file

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

Add activity to your manifest file

<activity android:name=”com.google.ads.AdActivity”
android:configChanges=”keyboard|keyboardHidden|orientation| screenLayout|uiMode|screenSize|smallestScreenSize”
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”/>

Step 3. Change project target

New version of admob sdk requires to set target level to 13 or above. It doesn’t mean that your application won’t works on devices with lower api level.

Right-click on your project then properties->android and select Project Build Taget to Android 3.2

Step 4. Add adView to layout.

Remeber to use RelativeLayout!

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:ads=”http://schemas.android.com/apk/lib/com.google.ads”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >

<org.anddev.andengine.opengl.view.RenderSurfaceView
android:id=”@+id/xmllayoutRenderSurfaceView”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:layout_centerInParent=”true”
android:gravity=”center” />
<com.google.ads.AdView
android:id=”@+id/adView”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignBottom=”@id/xmllayoutRenderSurfaceView”
ads:adSize=”BANNER”
ads:adUnitId=”<your code>”
ads:loadAdOnCreate=”true” />
</RelativeLayout>

Step 5. Add layout to activity
Your activity needs to extends LayoutBaseActivity

public class Main extends LayoutGameActivity
Override those two methods

@Override
protected int getLayoutID()
{
return R.layout.main;
}

@Override
protected int getRenderSurfaceViewID()
{
return R.id.xmllayoutRenderSurfaceView;
}

5 thoughts on “Integrasi AdMob dengan AndEngine

  1. permisi kak, saya mau nanya nih tentang membuat game di eclpse, barusan saya belajar membuat project accelerometer dengan andEngine gles1, dengan object bola di asset, udah berhasil sih, tapi yg saya tanyakan, cara ngebatasin layar biar bolannya ga keluar dari layar gimana yah ?
    terimakasih

  2. Apakah ada paket pelatihan yg khusus untuk making money di android?!?! kalo ada saya tertarik. Mohon diinfokan kepada saya kalo ada ya

    Terimakasih

    Anas lee

Leave a Reply

Your email address will not be published. Required fields are marked *