com.google.android.gms.ads.MobileAds Java Examples
The following examples show how to use
com.google.android.gms.ads.MobileAds.
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: MainActivity.java From USB_Mass_Storage_Enabler with MIT License | 6 votes |
void initADs() { if(enableADs) { //https://firebase.google.com/docs/admob/android/quick-start MobileAds.initialize(getApplicationContext(), getString(R.string.ad_app_id)); AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); Log.d(LOG_TAG, "Ads initialized.."); mInterstitialAd = new InterstitialAd(this); mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id)); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdClosed() { //requestNewInterstitial(); } }); requestNewInterstitial(); } }
Example #2
Source File: MainActivity.java From HeartbeatFixerForGCM with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { requestCheckout(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_actionbar)); if (savedInstanceState == null) { SettingsFragment fragment = new SettingsFragment(); fragment.setRetainInstance(false); getFragmentManager().beginTransaction() .add(R.id.container, fragment) .commit(); } mInventory = mCheckout.loadInventory(); MobileAds.initialize(this, "ca-app-pub-5964196502067291~1489720161"); }
Example #3
Source File: UnitySingleton.java From googleads-mobile-android-mediation with Apache License 2.0 | 6 votes |
/** * This method will initialize {@link UnityAds}. * * @param activity The Activity context. * @param gameId Unity Ads Game ID. * @return {@code true} if the {@link UnityAds} has initialized successfully, {@code false} * otherwise. */ public boolean initializeUnityAds(Activity activity, String gameId) { // Check if the current device is supported by Unity Ads before initializing. if (!UnityAds.isSupported()) { return false; } if (UnityAds.isInitialized()) { return true; } // Set mediation meta data before initializing. MediationMetaData mediationMetaData = new MediationMetaData(activity); mediationMetaData.setName("AdMob"); mediationMetaData.setVersion(MobileAds.getVersionString()); mediationMetaData.set("adapter_version", BuildConfig.VERSION_NAME); mediationMetaData.commit(); UnityAds.addListener(UnitySingleton.this); UnityAds.initialize(activity, gameId, false, true); return true; }
Example #4
Source File: MainActivity.java From admob-native-advanced-feed with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize the Mobile Ads SDK. MobileAds.initialize(this, getString(R.string.admob_app_id)); if (savedInstanceState == null) { // Create new fragment to display a progress spinner while the data set for the // RecyclerView is populated. Fragment loadingScreenFragment = new LoadingScreenFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(R.id.fragment_container, loadingScreenFragment); // Commit the transaction. transaction.commit(); // Update the RecyclerView item's list with menu items. addMenuItemsFromJson(); // Update the RecyclerView item's list with native ads. loadNativeAds(); } }
Example #5
Source File: AndroidAdMobRewardedVideo.java From QtAndroidTools with MIT License | 6 votes |
private void createRewardedVideoAd() { if(mRewardedVideoAd != null) { return; } SyncRunOnUiThread UiThread = new SyncRunOnUiThread(mActivityInstance, new SyncRunOnUiThread.SyncRunOnUiThreadListener() { public void runOnUIThread() { mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(mActivityInstance); mRewardedVideoAd.setRewardedVideoAdListener(mRewardedVideoListener); } }); UiThread.exec(); }
Example #6
Source File: MainActivity.java From funcodetuts with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MobileAds.initialize(getApplicationContext(), "YOUR UNIT ID"); 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 #7
Source File: MyActivity.java From googleads-mobile-android-examples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in // values/strings.xml. adView = findViewById(R.id.ad_view); // Set your test devices. Check your logcat output for the hashed device ID to // get test ads on a physical device. e.g. // "Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("ABCDEF012345")) // to get test ads on this device." MobileAds.setRequestConfiguration( new RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("ABCDEF012345")) .build()); // Create an ad request. PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build(); // Start loading the ad in the background. adView.loadAd(adRequest); }
Example #8
Source File: ScroballApplication.java From scroball with MIT License | 6 votes |
@Override public void onCreate() { super.onCreate(); Fabric.with(this, new Crashlytics()); FlowManager.init(this); MobileAds.initialize(this, "ca-app-pub-9985743520520066~4279780475"); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String userAgent = String.format(Locale.UK, "%s.%d", BuildConfig.APPLICATION_ID, BuildConfig.VERSION_CODE); String sessionKeyKey = getString(R.string.saved_session_key); LastfmApi api = new LastfmApi(); Caller caller = Caller.getInstance(); if (sharedPreferences.contains(sessionKeyKey)) { String sessionKey = sharedPreferences.getString(sessionKeyKey, null); lastfmClient = new LastfmClient(api, caller, userAgent, sessionKey); } else { lastfmClient = new LastfmClient(api, caller, userAgent); } scroballDB = new ScroballDB(); eventBus.register(this); }
Example #9
Source File: AdMobPlugin.java From cordova-admob-pro with MIT License | 6 votes |
@Override protected Object __prepareRewardVideoAd(String adId) { // safety check to avoid exceptoin in case adId is null or empty if(adId==null || adId.length()==0) adId = TEST_REWARDVIDEO_ID; RewardedVideoAd ad = MobileAds.getRewardedVideoAdInstance(getActivity()); ad.setRewardedVideoAdListener(new RewardVideoListener()); synchronized (mLock) { if (!mIsRewardedVideoLoading) { mIsRewardedVideoLoading = true; Bundle extras = new Bundle(); extras.putBoolean("_noRefresh", true); AdRequest adRequest = new AdRequest.Builder() .addNetworkExtrasBundle(AdMobAdapter.class, extras) .build(); ad.loadAd(adId, adRequest); } } return ad; }
Example #10
Source File: MainActivity.java From googleads-mobile-android-examples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize the Mobile Ads SDK. MobileAds.initialize(this, new OnInitializationCompleteListener() { @Override public void onInitializationComplete(InitializationStatus initializationStatus) {} }); refresh = findViewById(R.id.btn_refresh); startVideoAdsMuted = findViewById(R.id.cb_start_muted); videoStatus = findViewById(R.id.tv_video_status); refresh.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View unusedView) { refreshAd(); } }); refreshAd(); }
Example #11
Source File: MainActivity.java From android-ads with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize the Mobile Ads SDK. MobileAds.initialize(this, new OnInitializationCompleteListener() { @Override public void onInitializationComplete(InitializationStatus initializationStatus) {} }); refresh = findViewById(R.id.btn_refresh); startVideoAdsMuted = findViewById(R.id.cb_start_muted); videoStatus = findViewById(R.id.tv_video_status); refresh.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View unusedView) { refreshAd(); } }); refreshAd(); }
Example #12
Source File: MyActivity.java From android-ads with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); // Initialize the Mobile Ads SDK. MobileAds.initialize(this, new OnInitializationCompleteListener() { @Override public void onInitializationComplete(InitializationStatus initializationStatus) {} }); // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in // values/strings.xml. adView = findViewById(R.id.ad_view); // Create an ad request. Check your 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(); // Start loading the ad in the background. adView.loadAd(adRequest); }
Example #13
Source File: AdMob.java From capacitor-admob with MIT License | 6 votes |
@PluginMethod() public void initialize(PluginCall call) { /* Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 */ String appId = call.getString("appId", "ca-app-pub-3940256099942544~3347511713"); try { MobileAds.initialize(this.getContext(), appId); mViewGroup = (ViewGroup) ((ViewGroup) getActivity().findViewById(android.R.id.content)).getChildAt(0); call.success(); }catch (Exception ex) { call.error(ex.getLocalizedMessage(), ex); } }
Example #14
Source File: MainActivity.java From funcodetuts with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MobileAds.initialize(getApplicationContext(), "YOUR UNIT ID"); 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 #15
Source File: MainActivity.java From android-popular-movies-app with Apache License 2.0 | 5 votes |
/** * Initializes the Mobile Ads SDK and enables test ads. */ private void setupTestAds() { MobileAds.initialize(this, getString(R.string.ad_app_id)); // 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(); mMainBinding.adView.loadAd(adRequest); }
Example #16
Source File: GenerateShortcutHelper.java From TvAppRepo with Apache License 2.0 | 5 votes |
static void showVideoAd(Activity activity) { final RewardedVideoAd ad = MobileAds.getRewardedVideoAdInstance(activity); ad.setRewardedVideoAdListener(new RewardedVideoAdListener() { @Override public void onRewardedVideoAdLoaded() { ad.show(); } @Override public void onRewardedVideoAdOpened() { } @Override public void onRewardedVideoStarted() { } @Override public void onRewardedVideoAdClosed() { } @Override public void onRewarded(RewardItem rewardItem) { } @Override public void onRewardedVideoAdLeftApplication() { } @Override public void onRewardedVideoAdFailedToLoad(int i) { } }); ad.loadAd(activity.getString(R.string.reward_video_ad_unit_id), new AdRequest.Builder().build()); }
Example #17
Source File: AppController.java From Instagram-Profile-Downloader with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); PreferencesManager.init(this); DataObjectRepositry.init(this); Fabric.with(this, new Crashlytics()); MobileAds.initialize(this, getString(R.string.admob_app_id)); }
Example #18
Source File: TWOHsApp.java From twoh-android-material-design with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); MobileAds.initialize(this, "ca-app-pub-6916955256570875~9533087755"); }
Example #19
Source File: DetailActivity.java From NewsApp with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.activity_detail); makeUiFullscreen(); setupToolbar(); setupArticleAndListener(); newsRepository = NewsRepository.getInstance(this); getSavedState(); MobileAds.initialize(this, getString(R.string.admob_app_id)); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build(); binding.adView.loadAd(adRequest); binding.ivSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isSaved) { newsRepository.removeSaved(article.id); } else { newsRepository.save(article.id); } } }); }
Example #20
Source File: RemixedDungeon.java From remixed-dungeon with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EuConsent.check(this); playGames = new PlayGames(); MobileAds.initialize(this, Game.getVar(R.string.admob_app_id)); RemixedDungeon.activeMod(ModdingMode.activeMod()); if(!Utils.canUseClassicFont(uiLanguage())) { RemixedDungeon.classicFont(false); } ModdingMode.setClassicTextRenderingMode(RemixedDungeon.classicFont()); EventCollector.collectSessionData("font", String.valueOf(RemixedDungeon.classicFont())); setSelectedLanguage(); ItemSpritesDescription.readItemsDesc(); updateImmersiveMode(); DisplayMetrics metrics = new DisplayMetrics(); instance().getWindowManager().getDefaultDisplay().getMetrics(metrics); boolean landscape = metrics.widthPixels > metrics.heightPixels; if (Preferences.INSTANCE.getBoolean(Preferences.KEY_LANDSCAPE, false) != landscape) { landscape(!landscape); } Music.INSTANCE.enable(music()); Sample.INSTANCE.enable(soundFx()); }
Example #21
Source File: MainActivity.java From android-gradle-java-app-template with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MobileAds.initialize(this, getString(R.string.app_ads_id)); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment(), PlaceholderFragment.class.getSimpleName()) .commit(); } }
Example #22
Source File: MainActivity.java From KernelAdiutor with GNU General Public License v3.0 | 5 votes |
@Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); MainActivity activity = mRefActivity.get(); if (activity == null) return; /* * If root or busybox/toybox are not available, * launch text activity which let the user know * what the problem is. */ if (!mHasRoot || !mHasBusybox) { Intent intent = new Intent(activity, TextActivity.class); intent.putExtra(TextActivity.MESSAGE_INTENT, activity.getString(mHasRoot ? R.string.no_busybox : R.string.no_root)); intent.putExtra(TextActivity.SUMMARY_INTENT, mHasRoot ? "https://play.google.com/store/apps/details?id=stericson.busybox" : "https://www.google.com/search?site=&source=hp&q=root+" + Device.getVendor() + "+" + Device.getModel()); activity.startActivity(intent); activity.finish(); if (!BuildConfig.DEBUG) { // Send problem to analytics to collect stats Answers.getInstance().logCustom(new CustomEvent("Can't access") .putCustomAttribute("no_found", mHasRoot ? "no busybox" : "no root")); } return; } // Initialize Google Ads MobileAds.initialize(activity, "ca-app-pub-1851546461606210~9501142287"); // Execute another AsyncTask for license checking new LoadingTask(activity).execute(); }
Example #23
Source File: MainActivity_ListView.java From admobadapter with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_listview); //highly-recommended in Firebase docs to initialize things early as possible //test_admob_app_id is different with unit_id! you could get it in your Admob console MobileAds.initialize(getApplicationContext(), getString(R.string.test_admob_app_id)); initListViewItems(); initUpdateAdsTimer(); }
Example #24
Source File: MainActivity_RecyclerView_Express.java From admobadapter with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_recycleview); //highly-recommended in Firebase docs to initialize things early as possible //test_admob_app_id is different with unit_id! you could get it in your Admob console MobileAds.initialize(getApplicationContext(), getString(R.string.test_admob_app_id)); initRecyclerViewItems(); }
Example #25
Source File: MainActivity_ListView_Express.java From admobadapter with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_listview); //highly-recommended in Firebase docs to initialize things early as possible //test_admob_app_id is different with unit_id! you could get it in your Admob console MobileAds.initialize(getApplicationContext(), getString(R.string.test_admob_app_id)); initListViewItems(); }
Example #26
Source File: MainActivity_ListView_Banner.java From admobadapter with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_listview); //highly-recommended in Firebase docs to initialize things early as possible //test_admob_app_id is different with unit_id! you could get it in your Admob console MobileAds.initialize(getApplicationContext(), getString(R.string.test_admob_app_id)); initListViewItems(); }
Example #27
Source File: MainActivity_RecyclerView_Banner.java From admobadapter with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_recycleview); //highly-recommended in Firebase docs to initialize things early as possible //test_admob_app_id is different with unit_id! you could get it in your Admob console MobileAds.initialize(getApplicationContext(), getString(R.string.test_admob_app_id)); initRecyclerViewItems(); }
Example #28
Source File: MainActivity_RecyclerView.java From admobadapter with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_recycleview); //highly-recommended in Firebase docs to initialize things early as possible //test_admob_app_id is different with unit_id! you could get it in your Admob console MobileAds.initialize(getApplicationContext(), getString(R.string.test_admob_app_id)); initRecyclerViewItems(); initUpdateAdsTimer(); }
Example #29
Source File: RNAdMobRewardedVideoAdModule.java From react-native-admob with BSD 2-Clause "Simplified" License | 5 votes |
@ReactMethod public void requestAd(final Promise promise) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { RNAdMobRewardedVideoAdModule.this.mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(getCurrentActivity()); RNAdMobRewardedVideoAdModule.this.mRewardedVideoAd.setRewardedVideoAdListener(RNAdMobRewardedVideoAdModule.this); if (mRewardedVideoAd.isLoaded()) { promise.reject("E_AD_ALREADY_LOADED", "Ad is already loaded."); } else { mRequestAdPromise = promise; AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); if (testDevices != null) { for (int i = 0; i < testDevices.length; i++) { String testDevice = testDevices[i]; if (testDevice == "SIMULATOR") { testDevice = AdRequest.DEVICE_ID_EMULATOR; } adRequestBuilder.addTestDevice(testDevice); } } AdRequest adRequest = adRequestBuilder.build(); mRewardedVideoAd.loadAd(adUnitID, adRequest); } } }); }
Example #30
Source File: AdMobManager.java From commcare-android with Apache License 2.0 | 5 votes |
public static void initAdsForCurrentConsumerApp(Context context) { if (hasValidAdmobId()) { MobileAds.initialize(context, BuildConfig.ADMOB_ID); } }