Subscribe to web2feel.com
Subscribe to web2feel.com

Welcome to My Website

ShaTechs... Technology at your reach...
Showing posts with label AndEngine. Show all posts
Showing posts with label AndEngine. Show all posts

Putting ad from admob on your Android App

Posted by shajir Wednesday, June 8, 2011 0 comments

You can put admob on your android app successfully by following the steps

step1: Register your app in admob and get the publisher id.
step2: Change the AndroidManifest.xml by adding the following lines of code after closing activity
<meta-data android:value="a14d4b7f95df21d" android:name="ADMOB_PUBLISHER_ID" />
                 
         <receiver android:name="com.admob.android.ads.analytics.InstallReceiver" android:exported="true">
                 <intent-filter>
                         <action android:name="com.android.vending.INSTALL_REFERRER" />
                 </intent-filter>
         </receiver>
       
    <meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" />

step3: Change the publisher id with yours
step4: Add the following lines of code in main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.test"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/layout"
    >
  <com.admob.android.ads.AdView
       android:id="@+id/ad"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"     
       app:backgroundColor="#000000"
       app:primaryTextColor="#FFFFFF"
       app:secondaryTextColor="#CCCCCC"
       app:keywords="Android Game"
    />
</LinearLayout>
step5: create a new xml file and named as attr.xml and place in values folder and change it to
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="com.admob.android.ads.AdView">
        <attr name="backgroundColor" format="color" />
        <attr name="primaryTextColor" format="color" />
        <attr name="secondaryTextColor" format="color" />
        <attr name="keywords" format="string" />
        <attr name="refreshInterval" format="integer" />
    </declare-styleable>
</resources>

step6: Download admob-sdk-android.jar and pasted in libs folder and add to build path
step7: Done!!!
step8: For testing add the following lines code into your java file and run...
AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );

We can determine screen resolution of different android devices (phone and tablets) programmatically  in andengine and set camera width and height easily by adding the following code snippet 

public Engine onLoadEngine() {
        WindowManager w = getWindowManager();
        Display d = w.getDefaultDisplay();
        //d.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
        DisplayMetrics metrics = new DisplayMetrics();
        d.getMetrics(metrics);
       
        CAMERA_WIDTH = d.getWidth();
        CAMERA_HEIGHT = d.getHeight();

        final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new                                             RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera));
    }

Search This Blog