Sunday 6 October 2013

How to implement MoPub in android?


Step 1 :- Sign up Mopub For new Account.

Step 2 :- Add Your new application and download MoPub Sdk project.

get Your Ad Unit ID :- 1196015adbc045fa95b7e1a44cf56ad5 For your appication.

Step 3 :- Import Sdk project in Eclips.

Step 4 :- Create demo project and add mopub sdk project as a library project.

Step 5 :- Open Android mainfest.xml file and add this permission and activities.

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

  <activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidBrowser" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<activity android:name="com.millennialmedia.android.MMActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="keyboardHidden|orientation|keyboard" />
<activity android:name="com.millennialmedia.android.VideoPlayer" android:configChanges="keyboardHidden|orientation|keyboard" />

Step 6 :- open main.xml file and write this for banner code.

<com.mopub.mobileads.MoPubView
    android:id="@+id/adview"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"/>

Step 7 :- open MainActivity .java file write this code.

package com.example.demo;

import com.mopub.mobileads.MoPubView;
import com.mopub.mobileads.MoPubView.BannerAdListener;

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

public class MainActivity extends Activity {
    private MoPubView moPubView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      
          moPubView = (MoPubView) findViewById(R.id.adview);
            moPubView.setAdUnitId("1196015adbc045fa95b7e1a44cf56ad5");
            moPubView.loadAd();
           /* moPubView.setBannerAdListener((BannerAdListener) MainActivity.this);*/
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    protected void onDestroy() {
        moPubView.destroy();
        super.onDestroy();
    }
}

Step 8 :- Run project.

Out/Put :-


Download Demo Project :- https://dl.dropboxusercontent.com/u/109954727/Mopub.zip

Saturday 5 October 2013

How to implement Tapjoy in android?


Step 1 :- Signup to Tapjoy account :- https://dashboard.tapjoy.com/dashboard/apps/9522e8e5-283d-451d-8353-2f0886a662fb

Step 2 :- Add your application get tapjoyAppID and tapjoySecretKey .

For Example tapjoyAppID :- bba49f11-b87f-4c0f-9632-21aa810dd6f1

And tapjoySecretKey : - yiQIURFEeKm0zbOggubu

Step 3 :- Create Demo project.

Step 4 :- Open Android manifest.xml file add permission.

  <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

 <!-- Tapjoy -->
        <activity
            android:name="com.tapjoy.TJCOffersWebView"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity
            android:name="com.tapjoy.TapjoyFullScreenAdWebView"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity
            android:name="com.tapjoy.TapjoyDailyRewardAdWebView"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity
            android:name="com.tapjoy.TapjoyVideoView"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity
            android:name="com.tapjoy.TJAdUnitView"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
            android:hardwareAccelerated="true" />
        <activity
            android:name="com.tapjoy.mraid.view.ActionHandler"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity
            android:name="com.tapjoy.mraid.view.Browser"
            android:configChanges="orientation|keyboardHidden|screenSize" />

Step 5 :- open main.java file and add this code.

package com.tapjoy.easyapp;

import java.util.Hashtable;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tapjoy.TapjoyAwardPointsNotifier;
import com.tapjoy.TapjoyConnect;
import com.tapjoy.TapjoyConnectFlag;
import com.tapjoy.TapjoyConstants;
import com.tapjoy.TapjoyDisplayAdNotifier;
import com.tapjoy.TapjoyEarnedPointsNotifier;
import com.tapjoy.TapjoyFullScreenAdNotifier;
import com.tapjoy.TapjoyLog;
import com.tapjoy.TapjoyNotifier;
import com.tapjoy.TapjoyOffersNotifier;
import com.tapjoy.TapjoySpendPointsNotifier;
import com.tapjoy.TapjoyViewNotifier;
import com.tapjoy.TapjoyViewType;
import com.tapjoy.easyapp.R;


public class TapjoyEasyApp extends Activity implements View.OnClickListener
{
    TextView pointsTextView;
    TextView tapjoySDKVersionView;

    String displayText = "";
    boolean earnedPoints = false;
   
    // For the display ad.
    View adView;
    RelativeLayout relativeLayout;
    LinearLayout adLinearLayout;
   
    // UI elements
    private Button getPoints;
    private Button offers;
    private Button spendPoints;
    private Button awardPoints;
    private Button getFeaturedApp;
    private Button displayAd;
    private Button iapEvent;
   
    public static final String TAG = "TAPJOY EASY APP";
   
   
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {       
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        // Enables logging to the console.
        //TapjoyLog.enableLogging(true);
       
        // OPTIONAL: For custom startup flags.
        Hashtable<String, String> flags = new Hashtable<String, String>();
        flags.put(TapjoyConnectFlag.ENABLE_LOGGING, "true");
       
        // Connect with the Tapjoy server.  Call this when the application first starts.
        // REPLACE THE APP ID WITH YOUR TAPJOY APP ID.
        // REPLACE THE SECRET KEY WITH YOUR SECRET KEY.
        String tapjoyAppID = "bba49f11-b87f-4c0f-9632-21aa810dd6f1";
        String tapjoySecretKey = "yiQIURFEeKm0zbOggubu";
        // NOTE: This is the only step required if you're an advertiser.
        TapjoyConnect.requestTapjoyConnect(getApplicationContext(), tapjoyAppID, tapjoySecretKey, flags);

        // NOTE:  The get/spend/awardTapPoints methods will only work if your virtual currency
        // is managed by Tapjoy.
        //
        // For NON-MANAGED virtual currency, TapjoyConnect.getTapjoyConnectInsance().setUserID(...)
        // must be called after requestTapjoyConnect.

        // Get notifications whenever Tapjoy currency is earned.
        TapjoyConnect.getTapjoyConnectInstance().setEarnedPointsNotifier(new TapjoyEarnedPointsNotifier()
        {
            @Override
            public void earnedTapPoints(int amount)
            {
                earnedPoints = true;
                updateTextInUI("You've just earned " + amount + " Tap Points!");
            }
        });
       
        // Get notifications when Tapjoy views open or close.
        TapjoyConnect.getTapjoyConnectInstance().setTapjoyViewNotifier(new TapjoyViewNotifier()
        {
            @Override
            public void viewWillOpen(int viewType)
            {
                TapjoyLog.i(TAG, "viewWillOpen: " + getViewName(viewType));
            }
           
            @Override
            public void viewWillClose(int viewType)
            {
                TapjoyLog.i(TAG, "viewWillClose: " + getViewName(viewType));
            }
           
            @Override
            public void viewDidOpen(int viewType)
            {
                TapjoyLog.i(TAG, "viewDidOpen: " + getViewName(viewType));
            }
           
            @Override
            public void viewDidClose(int viewType)
            {
                TapjoyLog.i(TAG, "viewDidClose: " + getViewName(viewType));
            }
        });
       
        relativeLayout = (RelativeLayout)findViewById(R.id.RelativeLayout01);
        adLinearLayout = (LinearLayout)findViewById(R.id.AdLinearLayout);
       
        // This button launches the offers page when clicked.
        offers = (Button) findViewById(R.id.OffersButton);
        offers.setOnClickListener(this);
       
        // This button retrieves the virtual currency info from the server.
        getPoints = (Button) findViewById(R.id.GetPointsButton);
        getPoints.setOnClickListener(this);
       
        // This spends virtual currency for this device.
        spendPoints = (Button) findViewById(R.id.SpendPointsButton);
        spendPoints.setOnClickListener(this);
       
        // This awards virtual currency for this device.
        awardPoints = (Button) findViewById(R.id.AwardPointsButton);
        awardPoints.setOnClickListener(this);
       
        // This button displays the full screen ad when clicked.
        getFeaturedApp = (Button) findViewById(R.id.GetFeaturedApp);
        getFeaturedApp.setOnClickListener(this);
       
        // This button displays the Display ad when clicked.
        displayAd = (Button) findViewById(R.id.DisplayAd);
        displayAd.setOnClickListener(this);
       
        // Event tracking.
        iapEvent = (Button) findViewById(R.id.IAPEventButton);
        iapEvent.setOnClickListener(this);
       
        pointsTextView = (TextView)findViewById(R.id.PointsTextView);
       
        tapjoySDKVersionView = (TextView)findViewById(R.id.TapjoySDKVersionView);
        tapjoySDKVersionView.setText("SDK version: " + TapjoyConstants.TJC_LIBRARY_VERSION_NUMBER);
    }
   
    public void onClick(View v)
    {
        if (v instanceof Button)
        {
            final Button button = ((Button) v);
            int id = button.getId();
           
            switch (id)
            {
                //--------------------------------------------------------------------------------
                // GET TAP POINTS
                //--------------------------------------------------------------------------------
                case R.id.GetPointsButton:
                    // Disable button
                    button.setEnabled(false);
                    // Retrieve the virtual currency amount from the server.
                    TapjoyConnect.getTapjoyConnectInstance().getTapPoints(new TapjoyNotifier()
                    {
                        @Override
                        public void getUpdatePointsFailed(String error)
                        {
                            updateTextInUI("getTapPoints error: " + error);
                            reenableButtonInUI(button);
                        }
                       
                        @Override
                        public void getUpdatePoints(String currencyName, int pointTotal)
                        {
                            Log.i(TAG, "currencyName: " + currencyName);
                            Log.i(TAG, "pointTotal: " + pointTotal);
                           
                            if (earnedPoints)
                            {
                                updateTextInUI(displayText + "\n" + currencyName + ": " + pointTotal);
                                earnedPoints = false;
                            }
                            else
                            {
                                updateTextInUI(currencyName + ": " + pointTotal);
                            }
                           
                            reenableButtonInUI(button);
                        }
                    });
                    break;
                   
                //--------------------------------------------------------------------------------
                // SPEND TAP POINTS
                //--------------------------------------------------------------------------------
                case R.id.SpendPointsButton:
                    // Disable button
                    button.setEnabled(false);
                    // Spend virtual currency.
                    TapjoyConnect.getTapjoyConnectInstance().spendTapPoints(25, new TapjoySpendPointsNotifier()
                    {
                        @Override
                        public void getSpendPointsResponseFailed(String error)
                        {
                            updateTextInUI("spendTapPoints error: " + error);
                            reenableButtonInUI(button);
                        }
                       
                        @Override
                        public void getSpendPointsResponse(String currencyName, int pointTotal)
                        {
                            updateTextInUI(currencyName + ": " + pointTotal);
                            reenableButtonInUI(button);
                        }
                    });
                    break;
                   
                //--------------------------------------------------------------------------------
                // AWARD TAP POINTS
                //--------------------------------------------------------------------------------
                case R.id.AwardPointsButton:
                    // Disable button
                    button.setEnabled(false);
                    // Award virtual currency.
                    TapjoyConnect.getTapjoyConnectInstance().awardTapPoints(10, new TapjoyAwardPointsNotifier()
                    {
                        @Override
                        public void getAwardPointsResponseFailed(String error)
                        {
                            updateTextInUI("awardTapPoints error: " + error);
                            reenableButtonInUI(button);
                        }
                       
                        @Override
                        public void getAwardPointsResponse(String currencyName, int pointTotal)
                        {
                            updateTextInUI(currencyName + ": " + pointTotal);
                            reenableButtonInUI(button);
                        }
                    });
                    break;
                   
                //--------------------------------------------------------------------------------
                // SHOW OFFERS
                //--------------------------------------------------------------------------------
                case R.id.OffersButton:
                    // Disable button
                    button.setEnabled(false);
                    // Show the Offers web view from where users can download the latest offers for virtual currency.
                    TapjoyConnect.getTapjoyConnectInstance().showOffers(new TapjoyOffersNotifier()
                    {
                        @Override
                        public void getOffersResponse()
                        {
                            updateTextInUI("showOffers succeeded");
                            reenableButtonInUI(button);
                        }
                       
                        @Override
                        public void getOffersResponseFailed(String error)
                        {
                            updateTextInUI("showOffers error: " + error);
                            reenableButtonInUI(button);
                        }
                    });
                    break;
                   
                //--------------------------------------------------------------------------------
                // FULLSCREEN AD
                //--------------------------------------------------------------------------------
                case R.id.GetFeaturedApp:
                    // Disable button
                    button.setEnabled(false);
                    // Show the full screen ad.
                    TapjoyConnect.getTapjoyConnectInstance().getFullScreenAd(new TapjoyFullScreenAdNotifier()
                    {
                        @Override
                        public void getFullScreenAdResponseFailed(int error)
                        {
                            updateTextInUI("getFullScreenAd error: " + error);
                            reenableButtonInUI(button);
                        }
                       
                        @Override
                        public void getFullScreenAdResponse()
                        {
                            updateTextInUI("getFullScreenAd success");
                            TapjoyConnect.getTapjoyConnectInstance().showFullScreenAd();
                            reenableButtonInUI(button);
                        }
                    });
                    break;
                   
                // --------------------------------------------------------------------------------
                // BANNER/DISPLAY ADS
                // --------------------------------------------------------------------------------
                case R.id.DisplayAd:
                    // Disable button
                    button.setEnabled(false);
                    // Show the display/banner ad.
                    TapjoyConnect.getTapjoyConnectInstance().enableDisplayAdAutoRefresh(true);
                    TapjoyConnect.getTapjoyConnectInstance().getDisplayAd(TapjoyEasyApp.this, new TapjoyDisplayAdNotifier()
                    {
                        @Override
                        public void getDisplayAdResponseFailed(String error)
                        {
                            updateTextInUI("getDisplayAd error: " + error);
                            reenableButtonInUI(button);
                        }
                       
                        @Override
                        public void getDisplayAdResponse(View view)
                        {
                            // Using screen width, but substitute for the any width.
                            int desired_width = adLinearLayout.getMeasuredWidth();
                           
                            // Scale the display ad to fit incase the width is smaller than the display ad width.
                            adView = scaleDisplayAd(view, desired_width);
                           
                            updateDisplayAdInUI(adView);
                            updateTextInUI("getDisplayAd success");
                            reenableButtonInUI(button);
                        }
                    });
                    break;
                   
                // --------------------------------------------------------------------------------
                // --------------------------------------------------------------------------------
                case R.id.IAPEventButton:
                    TapjoyConnect.getTapjoyConnectInstance().sendIAPEvent("swag", 0.99f, 1, "usd");
                    break;
            }
        }
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
    }

    @Override
    protected void onResume()
    {
        super.onResume();

        // Re-enable auto-refresh when we regain focus.
        TapjoyConnect.getTapjoyConnectInstance().enableDisplayAdAutoRefresh(true);

        // Inform the SDK that the app has resumed.
        TapjoyConnect.getTapjoyConnectInstance().appResume();
    }
   
    @Override
    protected void onPause()
    {
        super.onPause();
       
        // Disable banner ad auto-refresh when the screen loses focus.
        TapjoyConnect.getTapjoyConnectInstance().enableDisplayAdAutoRefresh(false);
       
        // Inform the SDK that the app has paused.
        TapjoyConnect.getTapjoyConnectInstance().appPause();
    }

    //================================================================================
    // Helper Methods
    //================================================================================
    /**
     * Update the text view in the UI.
     * @param text                            Text to update the text view with.
     */
    private void updateTextInUI(final String text)
    {
        displayText = text;
       
        runOnUiThread(new Runnable()
        {
            @Override
            public void run()
            {
                if (pointsTextView != null)
                    pointsTextView.setText(text);
            }
        });
    }
   
    /**
     * Add the banner ad to our UI.
     * @param view                            Banner ad view.
     */
    private void updateDisplayAdInUI(final View view)
    {
        runOnUiThread(new Runnable()
        {
            @Override
            public void run()
            {
                // Remove all subviews of our ad layout.
                adLinearLayout.removeAllViews();
               
                // Add the ad to our layout.
                adLinearLayout.addView(view);
            }
        });
    }
   
    /**
     * REenable a button in the UI.
     * @param button                            Button to reenable.
     */
    private void reenableButtonInUI(final Button button)
    {
        runOnUiThread(new Runnable()
        {
            @Override
            public void run()
            {
                button.setEnabled(true);
            }
        });
    }
   
    /**
     * Scales a display ad view to fit within a specified width. Returns a resized (smaller) view if the display ad
     * is larger than the width. This method does not modify the view if the banner is smaller than the width (does not resize larger).
     * @param adView                                                Display Ad view to resize.
     * @param targetWidth                                   Width of the parent view for the display ad.
     * @return                                                              Resized display ad view.
     */
    private static View scaleDisplayAd(View adView, int targetWidth)
    {
        int adWidth = adView.getLayoutParams().width;
        int adHeight = adView.getLayoutParams().height;

        // Scale if the ad view is too big for the parent view.
        if (adWidth > targetWidth)
        {
            int scale;
            int width = targetWidth;
            Double val = Double.valueOf(width) / Double.valueOf(adWidth);
            val = val * 100d;
            scale = val.intValue();

            ((android.webkit.WebView) (adView)).getSettings().setSupportZoom(true);
            ((android.webkit.WebView) (adView)).setPadding(0, 0, 0, 0);
            ((android.webkit.WebView) (adView)).setVerticalScrollBarEnabled(false);
            ((android.webkit.WebView) (adView)).setHorizontalScrollBarEnabled(false);
            ((android.webkit.WebView) (adView)).setInitialScale(scale);

            // Resize banner to desired width and keep aspect ratio.
            LayoutParams layout = new LayoutParams(targetWidth, (targetWidth*adHeight)/adWidth);
            adView.setLayoutParams(layout);
        }

        return adView;
    }
   
    /**
     * Helper method to get the name of each view type.
     * @param type                            Tapjoy view type from the view notification callbacks.
     * @return                                Name of the view.
     */
    public String getViewName(int type)
    {
        String name = "";
        switch (type)
        {
            case TapjoyViewType.DAILY_REWARD_AD:
                name = "daily reward ad";
                break;
            case TapjoyViewType.FULLSCREEN_AD:
                name = "fullscreen ad";
                break;
            case TapjoyViewType.OFFER_WALL_AD:
                name = "offer wall ad";
                break;
            case TapjoyViewType.VIDEO_AD:
                name = "video ad";
                break;
            default:
                name = "undefined type: " + type;
                break;
        }
       
        return name;
    }
}



Step 6 :- Run project.

Out/Put.




Download Demo :- https://dl.dropboxusercontent.com/u/109954727/TapjoyEasyApp.zip


Thursday 3 October 2013

How to implement Tap For Tap in android?


Step 1 :- Signup account from this link :- http://r.tapfortap.com/4QCss

Step 2 :- Download sdk and add lib folder of your application.

Step 3 :- Open manifest.xml file and add this code.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.tapfortap"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
 <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
       
          <meta-data
        android:name="com.tapfortap.API_KEY"
        android:value="6f1711bc955e31786138702431d18c0b"/>
         
          <activity android:name="com.tapfortap.FullScreenAdActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
         
        <activity
            android:name="com.example.tapfortap.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Step 4 :- in Main.xml file


 <com.tapfortap.Banner
        android:id="@+id/banner"
        android:layout_width="320dip"
        android:layout_height="50dip"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
    />

Step 5 :- Run Project.

Out/Put :-



Download Link :- https://dl.dropboxusercontent.com/u/109954727/tapfortap.zip



How to implement appnext in android?


Step 1 :- Signup Appnext account :- http://appnext.com/

Download Sdk And Add in lib folder of your account.

Step 2 :- Add Your application and get code for interstitial and button.

Example :-
App launch :- 2b52f025-c87b-4146-9ef9-335475c3bcd7 and
More Games : - 97ce79d2-5fed-42e5-a8e8-b9ea89f8b298

Step 3 :- Create Demo application.

Step 4 :- Open android manifest.xml file.

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

  <receiver android:name="com.appnext.appnextsdk.ReferralReceiver" android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>

Step 5 :- Open java file and add this code.

 package com.example.appnext;

import com.appnext.appnextsdk.Appnext;

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

public class MainActivity extends Activity {
    Appnext appnext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        appnext = new Appnext(this);
       
        appnext.setAppID("2b52f025-c87b-4146-9ef9-335475c3bcd7");
       
       
        appnext.addMoreGamesLeft(" 97ce79d2-5fed-42e5-a8e8-b9ea89f8b298");
       
        appnext.addMoreGamesRight(" 97ce79d2-5fed-42e5-a8e8-b9ea89f8b298");
       
        appnext.showBubble();
    }
@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    appnext.hideBubble();
    super.onDestroy();
}
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}


Step 6 :- Run Project.

Opt/Put :-




Download Demo Code :- https://dl.dropboxusercontent.com/u/109954727/Appnext.zip
 

How to implement In-Mobi ads in android?


Step 1 :- Signup in-mobi as a ad-network.   http://www.inmobi.com/

Step 2:- Select my properties and add new property.

Step 3 :- Get Property ID : 4bf5be5909154b828ea4a6f87757f49e

Step 4 :- Add Permission in manifest file.

Download jar file :- InMobiAdNetwork-3.7.1.jar and InMobiCommons-3.7.1.jar

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


 <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" />

Add activity in your application tag

 <activity android:name="com.inmobi.androidsdk.IMBrowserActivity"
     android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
     android:hardwareAccelerated="true" />

Step 5 :- Add this code in main.xml file

  <com.inmobi.androidsdk.IMAdView android:layout_width="320dp"
android:layout_height="50dp" android:id="@+id/imAdview" appId="4bf5be5909154b828ea4a6f87757f49e"
adSize="15" />

Step 6 :- Add this in main.java file.

package com.example.inmobi;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.InflateException;
import android.view.Menu;
import android.widget.Toast;

import com.inmobi.androidsdk.IMAdInterstitial;
import com.inmobi.androidsdk.IMAdInterstitialListener;
import com.inmobi.androidsdk.IMAdRequest;
import com.inmobi.androidsdk.IMAdRequest.ErrorCode;
import com.inmobi.androidsdk.IMAdView;

public class MainActivity extends Activity {
    IMAdView imAdView;
    private IMAdInterstitial mIMAdInterstitial;
  private static String LOG_TAG="InMobiAndroidSampleApp";
private IMAdRequest mAdRequest;
    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
         imAdView = (IMAdView) findViewById(R.id.imAdview);
       
         try {   
               
               
                mAdRequest = new IMAdRequest();
                imAdView.setIMAdRequest(mAdRequest);

                //load new ad has to be called explicitly..Just adding xml to layout wont call load new ad
                imAdView.loadNewAd(mAdRequest);
               
                // initialize an interstitial ad
                mIMAdInterstitial = new IMAdInterstitial(this,
                        "4bf5be5909154b828ea4a6f87757f49e");
                mIMAdInterstitial.loadNewAd(mAdRequest);
                // set the listener if the app has to know ad status notifications
                mIMAdInterstitial.setIMAdInterstitialListener(mIMAdInListener);   

            }catch(InflateException e){
               
                e.printStackTrace();
            }catch(IllegalArgumentException e){
               
                e.printStackTrace();
            }catch(NullPointerException e){
               
                e.printStackTrace();
            }
       
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    private IMAdInterstitialListener mIMAdInListener = new IMAdInterstitialListener() {

        @Override
        public void onShowAdScreen(IMAdInterstitial adInterstitial) {
            Log.i(LOG_TAG,
                    "InMobiAdActivity-> onShowAdScreen, adInterstitial: "
                            + adInterstitial);
        }

        @Override
        public void onDismissAdScreen(IMAdInterstitial adInterstitial) {
            Log.i(LOG_TAG,
                    "InMobiAdActivity-> onDismissAdScreen, adInterstitial: "
                            + adInterstitial);

        }

        @Override
        public void onAdRequestFailed(IMAdInterstitial adInterstitial,
                ErrorCode errorCode) {
            Log.i(LOG_TAG,
                    "InMobiAdActivity-> onAdRequestFailed, adInterstitial: "
                            + adInterstitial + " ,errorCode: " + errorCode);
            Toast.makeText(MainActivity.this,
                    "Interstitial Ad failed to load. Errorcode: " + errorCode,
                    Toast.LENGTH_SHORT).show();
       
        }

        @Override
        public void onAdRequestLoaded(IMAdInterstitial adInterstitial) {
            Log.i(LOG_TAG,
                    "InMobiAdActivity-> onAdRequestLoaded, adInterstitial: "
                            + adInterstitial);
            Toast.makeText(MainActivity.this, "Interstitial Ad Loaded.",
                    Toast.LENGTH_SHORT).show();
           
            mIMAdInterstitial.show();
           
        }

        @Override
        public void onLeaveApplication(IMAdInterstitial adInterstitial) {
            Log.i(LOG_TAG,
                    "InMobiAdActivity-> onLeaveApplication, adInterstitial: "
                            + adInterstitial);
        }
    };
   
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
       
        if(imAdView!=null)
                imAdView.destroy();
           
            if(mIMAdInterstitial!=null)
                mIMAdInterstitial.destroy();
    }
}

Step 7 :- Run project.

Out/put :-




Download Demo Project : -  https://dl.dropboxusercontent.com/u/109954727/InMobi.zip








Wednesday 2 October 2013

How to implement ad-mob in android?

Step 1 :- Get site id From your account like a151fa47259f783.

Step 2 :- Create new Project implement for ads.

Step 3 :- ADD Permission in manifest file in your project.

<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" />

Step 4 :-  add activity in application at manifest file.

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

Step 5 :- Finally manifest file look like this.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ad_mob"
    android:versionCode="1"
    android:versionName="1.0" >

    <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" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
       
         <activity android:name="com.google.ads.AdActivity"
                      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
        
        <activity
            android:name="com.example.ad_mob.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Step 6 :- Add GoogleAdMobAdsSdk-6.4.1.jar in your lib folder at your projects.

Step 7 :- Add main.xml

<com.google.ads.AdView
      xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/web"
        android:layout_width="fill_parent"
        android:layout_height="50sp"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="a151fa47259f783"
        android:background="@android:color/transparent" />


Step 8 :- open main.java file and add this code.

    AdView adview = (AdView)findViewById(R.id.web);
        AdRequest re = new AdRequest();
         adview.loadAd(re);


Step 9 :- Run this code.

Out/Put



Download link : - https://dl.dropboxusercontent.com/u/109954727/admob.zip