Java Code Examples for com.google.android.gms.ads.AdView#loadAd()

The following examples show how to use com.google.android.gms.ads.AdView#loadAd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchActivity.java    From aMuleRemote with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    mApp = (AmuleRemoteApplication) getApplication();

    if (DEBUG) Log.d(TAG, "SearchActivity.onCreate: Calling super");
    super.onCreate(savedInstanceState);
    if (DEBUG) Log.d(TAG, "SearchActivity.onCreate: Back from super");
    
    if (DEBUG) Log.d(TAG, "SearchActivity.onCreate: Calling setContentView");
    setContentView(R.layout.act_search);
    if (DEBUG) Log.d(TAG, "SearchActivity.onCreate: Back from setContentView");

    getSupportActionBar().setTitle(R.string.search_title);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mFragManager = getSupportFragmentManager();

    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("TEST_DEVICE_ID")
            .build();
    adView.loadAd(adRequest);

}
 
Example 2
Source File: MainActivityFragment.java    From ud867 with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_main, container, false);

    AdView mAdView = (AdView) root.findViewById(R.id.adView);
    // Create an ad request. Check logcat output for the hashed device ID to
    // get test ads on a physical device. e.g.
    // "Use AdRequest.Builder.addTestDevice("ABCDEF012345") to get test ads on this device."
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();
    mAdView.loadAd(adRequest);
    return root;

}
 
Example 3
Source File: BaseAdsActivity.java    From twoh-android-material-design with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice("22FFB74E3E00DEC909938864EE0B401E").build();
    mAdView.loadAd(adRequest);

    System.out.println("Outer class "+this.getClass().getSimpleName());

    Bundle bundle = new Bundle();
    bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, this.getClass().getSimpleName());
    bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "activity");
    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle);

    initInterstitial();

}
 
Example 4
Source File: AdvancedOptions.java    From USB_Mass_Storage_Enabler with MIT License 5 votes vote down vote up
void initADs() {

		if(MainActivity.enableADs) {
		/*AdView mAdView = (AdView) findViewById(R.id.adViewInSettings);
		mAdView.loadAd(new AdRequest.Builder().build());*/

			AdView mAdView1 = (AdView) findViewById(R.id.adViewInSettingsBottom);
			mAdView1.loadAd(new AdRequest.Builder().build());
			Log.d(LOG_TAG, "Ads initialized in Settings Activity..");
		}
	}
 
Example 5
Source File: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 5 votes vote down vote up
private void loadBanner() {
  // Create an ad request.
  adView = new AdView(this);
  adView.setAdUnitId(AD_UNIT_ID);
  adContainerView.removeAllViews();
  adContainerView.addView(adView);

  AdSize adSize = getAdSize();
  adView.setAdSize(adSize);

  AdRequest adRequest = new AdRequest.Builder().build();

  // Start loading the ad in the background.
  adView.loadAd(adRequest);
}
 
Example 6
Source File: ChangeBrightness.java    From NightSight with Apache License 2.0 5 votes vote down vote up
void initialize() {

        parent = (RelativeLayout) findViewById(R.id.parent);
        adView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);

        EventBus.getDefault().register(new Darkness());
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        colorAdapter = new ColorAdapter(this);
        colorAdapter.setColorData(getMockData());
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(staggeredGridLayoutManager);
        //    GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(), 3);
        //   recyclerView.setLayoutManager(gridLayoutManager);
        //   recyclerView.setHasFixedSize(true);
        recyclerView.setAdapter(colorAdapter);

        sharedPrefs = new SharedPrefs(this);
        seekBar = (SeekBar) findViewById(R.id.seekBar1);
        startStop = (Button) findViewById(R.id.startStop);
        seekValue = (TextView) findViewById(R.id.seekPercentage);
        seekValue.setText("( Brightness " + sharedPrefs.getBrightness() / 2 + "% )");

        seekBar.setMax(200);
        seekBar.setProgress(sharedPrefs.getBrightness());

        if (sharedPrefs.isService()) {
            startStop.setText("Stop");

        } else {
            startStop.setText("Start");
        }


    }
 
Example 7
Source File: TestAdMobClassicActivity.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
private AdView createadmob() {
    AdView mAdView = new AdView(this);
    mAdView.setAdSize(AdSize.MEDIUM_RECTANGLE);
    mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
    mAdView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    // Create an ad request.
    AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
    if (admob_test_mode)
        // Optionally populate the ad request builder.
        adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
    // Start loading the ad.
    mAdView.loadAd(adRequestBuilder.build());
    return mAdView;
}
 
Example 8
Source File: AboutActivity.java    From GithubTrends with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);
    ((TextView) findViewById(R.id.about)).setText(Html.fromHtml(aboutText));

    final AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
}
 
Example 9
Source File: MainActivity.java    From funcodetuts with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AdView adView = (AdView) this.findViewById(R.id.adMob);
    //request TEST ads to avoid being disabled for clicking your own ads
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)// This is for emulators
            //test mode on DEVICE (this example code must be replaced with your device uniquq ID)
            .addTestDevice("2EAB96D84FE62876379A9C030AA6A0AC") // Nexus 5
            .build();
    adView.loadAd(adRequest);
}
 
Example 10
Source File: AdMobComboProvider.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void displayBanner() {

    adView = new AdView(Game.instance());
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId(Game.getVar(R.string.easyModeAdUnitId));
    adView.setBackgroundColor(Color.TRANSPARENT);
    adView.setAdListener(new AdmobBannerListener());

    adView.loadAd(AdMob.makeAdRequest());
}
 
Example 11
Source File: AdMobManager.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
public static void requestBannerAdForView(Context context, FrameLayout adContainer,
                                          AdLocation adLocation) {
    if (hasValidAdmobId()) {
        // TODO: It's probably bad not to validate this in any way, but any mechanism for doing
        // so would defeat the purpose of having made this configurable from the consumer apps resources
        AdView adView = buildBannerAdView(context, adLocation);
        adContainer.setVisibility(View.VISIBLE);
        adContainer.addView(adView);

        AdRequest adRequest = buildAdRequest();
        adView.loadAd(adRequest);
    } else {
        adContainer.setVisibility(View.GONE);
    }
}
 
Example 12
Source File: HowToUseActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    }catch (Exception e){
        Log.e(TAG, "showBannerAd: "+e );
    }
}
 
Example 13
Source File: MainActivity.java    From HeartbeatFixerForGCM with Apache License 2.0 4 votes vote down vote up
private void showAd() {
    Log.v(TAG, "showAd");
    if (!mShowAd) {
        mShowAd = true;
        mAdView = new AdView(this);
        mAdView.setAdSize(AdSize.SMART_BANNER);
        mAdView.setAdUnitId("ca-app-pub-5964196502067291/5460955376");
        mAdView.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                Log.v(TAG, "onAdClosed");
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                Log.v(TAG, "onAdFailedToLoad, errorCode: " + errorCode);
            }

            @Override
            public void onAdLeftApplication() {
                Log.v(TAG, "onAdLeftApplication");
            }

            @Override
            public void onAdOpened() {
                Log.v(TAG, "onAdOpened");
            }

            @Override
            public void onAdLoaded() {
                Log.v(TAG, "onAdLoaded");
            }

            @Override
            public void onAdClicked() {
                Log.v(TAG, "onAdClicked");
            }

            @Override
            public void onAdImpression() {
                Log.v(TAG, "onAdImpression");
            }
        });
        getRootViewGroup().addView(mAdView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mAdView.loadAd(new AdRequest.Builder().build());
    }
}
 
Example 14
Source File: SearchActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    }catch (Exception e){
        Log.e(TAG, "showBannerAd: "+e );
    }
}
 
Example 15
Source File: ViewProfileActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    }catch (Exception e){
        Log.e(TAG, "showBannerAd: "+e );
    }
}
 
Example 16
Source File: DownloadIGTVFragment.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {

        adView = new AdView(getActivity());
        adView.setAdSize(AdSize.MEDIUM_RECTANGLE);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "showBannerAd: " + e);
    }
}
 
Example 17
Source File: MainActivity.java    From GDPR-Admob-Android with MIT License 4 votes vote down vote up
private void loadBanner() {
    AdView adView = findViewById(R.id.adView);
    // You have to pass the AdRequest from ConsentSDK.getAdRequest(this) because it handle the right way to load the ad
    adView.loadAd(ConsentSDK.getAdRequest(this));
}
 
Example 18
Source File: ConsentSDK.java    From GDPR-Admob-Android with MIT License 4 votes vote down vote up
public static void initDummyBanner(Context context) {
    AdView adView = new AdView(context);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(DUMMY_BANNER);
    adView.loadAd(new AdRequest.Builder().build());
}
 
Example 19
Source File: FavouriteFragment.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(getActivity());
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    }catch (Exception e){
        Log.e(TAG, "showBannerAd: "+e );
    }
}
 
Example 20
Source File: StoriesOverview.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(getActivity());
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "showBannerAd: " + e);
    }
}