Java Code Examples for com.google.android.gms.ads.MobileAds#initialize()

The following examples show how to use com.google.android.gms.ads.MobileAds#initialize() . 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 HeartbeatFixerForGCM with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: MainActivity.java    From funcodetuts with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: ScroballApplication.java    From scroball with MIT License 6 votes vote down vote up
@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 4
Source File: MainActivity.java    From admob-native-advanced-feed with Apache License 2.0 6 votes vote down vote up
@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: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 5 votes vote down vote up
@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) {}
    });

    // Create the InterstitialAd and set the adUnitId.
    interstitialAd = new InterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialAd.setAdUnitId(AD_UNIT_ID);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            Toast.makeText(MyActivity.this, "onAdLoaded()", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(MyActivity.this,
                    "onAdFailedToLoad() with error code: " + errorCode,
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdClosed() {
            startGame();
        }
    });

    // Create the "retry" button, which tries to show an interstitial between game plays.
    retryButton = findViewById(R.id.retry_button);
    retryButton.setVisibility(View.INVISIBLE);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showInterstitial();
        }
    });

    startGame();
}
 
Example 6
Source File: MainUI.java    From Busybox-Installer-No-Root with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_ui);

    context = getApplicationContext();

    MobileAds.initialize(this);

    mAdView = findViewById(R.id.adView);
    mAdView.loadAd(new AdRequest.Builder().build());

    Toolbar toolbar = findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            mAdView.loadAd(new AdRequest.Builder().build());
        }
    });

    if(savedInstanceState == null){
        MenuItem selected = navigationView.getMenu().findItem(R.id.method1);
        selected.setCheckable(true);
        selected.setChecked(true);
        newFragment(0);
    }
}
 
Example 7
Source File: MainActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ...
    // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
    MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
}
 
Example 8
Source File: GoogleAdActivity.java    From FastLib with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_google_ad);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {
        }
    });

    // Create the InterstitialAd and set the adUnitId.
    interstitialAd = new InterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialAd.setAdUnitId(AD_UNIT_ID);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            ToastUtil.show("onAdLoaded()");
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            ToastUtil.show("onAdFailedToLoad() with error code: " + errorCode);
        }

        @Override
        public void onAdClosed() {
            startGame();
        }
    });

    // Create the "retry" button, which tries to show an interstitial between game plays.
    retryButton = findViewById(R.id.retry_button);
    retryButton.setVisibility(View.INVISIBLE);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showInterstitial();
        }
    });

    startGame();
}
 
Example 9
Source File: AdRecyclerHolder.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 5 votes vote down vote up
void loadAd(Context c){
    if(c == null) return;
    if (Settings.displayAds) {
        MobileAds.initialize(c, "ca-app-pub-8285849835347571~6235180375");
        AdRequest adRequest = new AdRequest.Builder().build();
        ad.loadAd(adRequest);
    }
}
 
Example 10
Source File: MainActivity.java    From android-gradle-java-app-template with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: TWOHsApp.java    From twoh-android-material-design with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    MobileAds.initialize(this, "ca-app-pub-6916955256570875~9533087755");
}
 
Example 12
Source File: MainActivity.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!Premium.isPremium(this)) {
        MobileAds.initialize(this);
    }
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    setContentView(R.layout.activity_main);
    setupToolbar();
    bindView();
    showDialogRate();
    checkLicense();
}
 
Example 13
Source File: AdMobManager.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
public static void initAdsForCurrentConsumerApp(Context context) {
    if (hasValidAdmobId()) {
        MobileAds.initialize(context, BuildConfig.ADMOB_ID);
    }
}
 
Example 14
Source File: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_my);

  Button btn = findViewById(R.id.btn);
  btn.setOnClickListener(
      new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          loadBanner(getAdSize());
        }
      });

  // Initialize the Mobile Ads SDK.
  MobileAds.initialize(this);

  // 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());

  adContainerView = findViewById(R.id.ad_view_container);

  // Since we're loading the banner based on the adContainerView size, we need to wait until this
  // view is laid out before we can get the width.
  adContainerView.getViewTreeObserver().addOnGlobalLayoutListener(
      new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
      if (!initialLayoutComplete) {
        initialLayoutComplete = true;
        loadBanner(getAdSize());
      }
    }
  });
}
 
Example 15
Source File: MainActivity.java    From Android-POS with MIT License 5 votes vote down vote up
private void mobileAdsInitialize() {
    MobileAds.initialize(this,
            getResources().getString(R.string.app_add_id));

    mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

}
 
Example 16
Source File: MainActivity_ListView_Banner.java    From admobadapter with Apache License 2.0 5 votes vote down vote up
@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 17
Source File: HomeFragment.java    From Newslly with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view= inflater.inflate(R.layout.fragment_home, container, false);

    MobileAds.initialize(getActivity(), "ca-app-pub-3948730596862295~8706925921");
    mAdView = view.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    System.out.println("on create view called");
    viewPager = (ViewPager) view.findViewById(R.id.viewpager);
    setupViewPager(viewPager,view);
    return view;
}
 
Example 18
Source File: MainActivity_ListView.java    From admobadapter with Apache License 2.0 5 votes vote down vote up
@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 19
Source File: AppApplication.java    From GooglePlayServiceLocationSupport with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-5883105630361246~9038606611");
}
 
Example 20
Source File: MainActivity.java    From Android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    MobileAds.initialize(this, "ca-app-pub-3341550634619945~1422870532");
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
            .setDefaultFontPath("fonts/brownregular.ttf")
            .setFontAttrId(R.attr.fontPath)
            .build()
    );
    prefs = getSharedPreferences("Plex", Activity.MODE_PRIVATE);
    editor = prefs.edit();


    mContext = MainActivity.this;
    btn_one =  findViewById(R.id.btn_one);
    btn_two =  findViewById(R.id.btn_two);
    btn_three = findViewById(R.id.btn_three);
    btn_four =  findViewById(R.id.btn_four);
    btn_five =  findViewById(R.id.btn_five);


    btn_one.setOnClickListener(this);
    btn_two.setOnClickListener(this);
    btn_three.setOnClickListener(this);
    btn_four.setOnClickListener(this);
    btn_five.setOnClickListener(this);

    upadate_retrofit();
    get_API_keys();
    analytics();
    if(!isPackageInstalled()){
        final Dialog dialog = new Dialog(MainActivity.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.alertdialog_update);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.setCancelable(true);
        dialog.show();

        Button update_btn = dialog.findViewById(R.id.update_btn);
        TextView title_view = dialog.findViewById(R.id.title);
        TextView message_update = dialog.findViewById(R.id.message_update);
        ImageView background_image = dialog.findViewById(R.id.background_image);
        background_image.setImageResource(R.drawable.mxplayer);
        title_view.setText("");
        message_update.setText("For better streaming quality and subtitle \nDownload MX Player app");
        update_btn.setOnClickListener(new View.OnClickListener() {
                                          @Override
                                          public void onClick(View v) {
                                              dialog.cancel();
                                              final String appPackageName = "com.mxtech.videoplayer.ad"; // getPackageName() from Context or Activity object
                                              try {
                                                  startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
                                              } catch (android.content.ActivityNotFoundException anfe) {
                                                  startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
                                              }
                                          }
                                      });
    }
}