Trying to launch an Application with Airpush ads

1.7k Views Asked by At

I want to make an Application running with Airpush ads. You can see my code below but I'm totally confused now.. The good point is, that my app is running. The bad point is: without ads. Does anybody know why or knows a correct code?

package com.syntaix.appleclicker;

import com.enkk.nrfk181061.AdListener.AdType;
import com.enkk.nrfk181061.*;
import com.enkk.nrfk181061.AdListener.BannerAdListener;

import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity implements BannerAdListener {

    private Prm prm;
    int counter = 10;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AdView adView = new AdView(this, AdView.BANNER_TYPE_IN_APP_AD,
                AdView.PLACEMENT_TYPE_INTERSTITIAL, false, false,
                AdView.ANIMATION_TYPE_LEFT_TO_RIGHT);
        adView.setAdListener(this);

        if (prm == null)
            prm = new Prm(this, adCallbackListener, false);
            prm.runAppWall();                               //this will start the AppWall ad but it will not show you AppWall instantly.  



        try {
            prm.runCachedAd(this, AdType.appwall);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  


        final TextView text = (TextView) findViewById(R.id.TextView01);
        final ImageView image = (ImageView) findViewById(R.id.appel);
        image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (counter > 0) {
                    counter--;
                    text.setText("" + counter);
                }
                if (counter == 0) {
                    text.setText("Finished");
                }
            }
        });

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

     AdListener adCallbackListener=new AdListener() {

            @Override
            public void onSDKIntegrationError(String message) {
            //Here you will receive message from SDK if it detects any integration issue.
            }

            public void onSmartWallAdShowing() {
            // This will be called by SDK when it’s showing any of the SmartWall ad.
            }

            @Override
            public void onSmartWallAdClosed() {
            // This will be called by SDK when the SmartWall ad is closed.
            }

            @Override
            public void onAdError(String message) {
            //This will get called if any error occurred during ad serving.
            }
            @Override
            public void onAdCached(AdType arg0) {
            //This will get called when an ad is cached. 

            }
             @Override
            public void noAdAvailableListener() {
            //this will get called when ad is not available 

            }
         };


         AdListener.BannerAdListener adlistener = new AdListener.BannerAdListener() {

             @Override
             public void onAdClickListener()
             {
             //This will get called when ad is clicked.
             }

             @Override
             public void onAdLoadedListener()
             {
             //This will get called when an ad has loaded.
             }

             @Override
             public void onAdLoadingListener()
             {
             //This will get called when a rich media ad is loading.
             }

             @Override
             public void onAdExpandedListner()
             {
             //This will get called when an ad is showing on a user's screen. This may cover the whole UI.
             }

             @Override
             public void onCloseListener()
             {
             //This will get called when an ad is closing/resizing from an expanded state.
             }

             @Override
             public void onErrorListener(String message)
             {
             //This will get called when any error has occurred. This will also get called if the SDK notices any integration mistakes.
             }
             @Override
              public void noAdAvailableListener() {
              //this will get called when ad is not available 

             }
        };


    @Override
    public void onBackPressed() {
       try{
         prm.runCachedAd(this, AdType.smartwall);   // for closing the activity call finish() method in onSmartWallClosed(). 
       }catch (Exception e) {                       // close the activity if ad is not available. 
         //finish();
       }
    }

    @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;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container,
                    false);
            return rootView;
        }
    }

    @Override
    public void noAdAvailableListener() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAdClickListener() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAdExpandedListner() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAdLoadedListener() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAdLoadingListener() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onCloseListener() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onErrorListener(String arg0) {
        // TODO Auto-generated method stub

    }

    }
1

There are 1 best solutions below

0
On

Try with this code,

Don't forget your Activity must implements AdListener and OptinListener

Prm air = null;
    AdType adtype;

    // in your oncreate

    air = new Prm(MainActivity.this, this, true); // true - ads stored in cache
        try {
            air.runCachedAd(MainActivity.this, AdType.smartwall);
        } catch (Exception e) {
             e.printStackTrace();
        }
         air.runSmartWallAd();

        Prm.setOptinListener(this);



    @Override
    public void noAdAvailableListener() {
        // TODO Auto-generated method stub
        Log.e("MainActivity", "noAdAvailableListener");
    }


    @Override
    public void onAdCached(AdType arg0) {
        // TODO Auto-generated method stub
        adtype = arg0;
        Log.e("MainActivity - onAdCached", arg0 + "");
    }


    @Override
    public void onAdError(String arg0) {
        // air.runSmartWallAd();
        Log.e("MainActivity - onAdError", arg0 + "");
    }


    @Override
    public void onSDKIntegrationError(String arg0) {
        // TODO Auto-generated method stub
        Log.e("MainActivity - onSDKIntegrationError", arg0 + "");
    }

    @Override
    public void onSmartWallAdClosed() {
        air.runSmartWallAd();
        Log.e("MainActivity - onSmartWallAdClosed", "Executed");
    }


    @Override
    public void onSmartWallAdShowing() {
        Log.e("MainActivity - onSmartWallAdShowing", "Executed");
    }


    @Override
    public void optinResult(boolean isOpted_in) {
        if (isOpted_in) {
            Toast.makeText(MainActivity.this, "You have accepted the EULA.",
                    Toast.LENGTH_SHORT).show();
        } else
            Toast.makeText(MainActivity.this,
                    "You have note accepted the EULA.", Toast.LENGTH_SHORT)
                    .show();
    }

    @Override
    public void showingDialog() {
        // TODO Auto-generated method stub

        Log.e("MainActivity - showingDialog", "Executed");
    }