當前位置: 首頁>>代碼示例>>Java>>正文


Java MobileAds類代碼示例

本文整理匯總了Java中com.google.android.gms.ads.MobileAds的典型用法代碼示例。如果您正苦於以下問題:Java MobileAds類的具體用法?Java MobileAds怎麽用?Java MobileAds使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MobileAds類屬於com.google.android.gms.ads包,在下文中一共展示了MobileAds類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@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);
    }
 
開發者ID:CatalinPrata,項目名稱:funcodetuts,代碼行數:17,代碼來源:MainActivity.java

示例2: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@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.
        loadNativeAd();
    }
}
 
開發者ID:googlecodelabs,項目名稱:admob-native-advanced-feed,代碼行數:25,代碼來源:MainActivity.java

示例3: doInBackground

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@Override
protected Boolean doInBackground(Void... voids) {
    FirebaseApp.initializeApp(mContext);
    MobileAds.initialize(mContext.getApplicationContext(), mContext.getResources().getString(R.string.app_id));
    FirebaseAnalytics.getInstance(mContext).setAnalyticsCollectionEnabled(true);
    FirebaseAnalytics.getInstance(mContext).setMinimumSessionDuration(2000);
    //dc.getGenres(null, null);

    AppVersionTracking current = new AppVersionTracking(BuildConfig.VERSION_CODE, BuildConfig.VERSION_NAME);

    if(!getAppPrefs().checkState()){
        getAppPrefs().saveOrUpdateVersionNumber(current);
        return false;
    }
    AppVersionTracking saved = getAppPrefs().getSavedVersions();
    if((BuildConfig.VERSION_CODE > saved.getCode())) {
        getAppPrefs().saveOrUpdateVersionNumber(current);
        return true;
    }
    return null;
}
 
開發者ID:wax911,項目名稱:anitrend-app,代碼行數:22,代碼來源:MainPresenter.java

示例4: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    MobileAds.initialize(getApplicationContext(), getString(R.string.banner_ad_app_id));
    initializeAd();

    plSwitch = (PulsatorLayout) findViewById(R.id.pl_switch);
    findViewById(R.id.ib_switch).setOnClickListener(this);
    findViewById(R.id.iv_question).setOnClickListener(this);

    serviceRunning = isClipboardServiceRunning(ClipboardService.class);
    if (serviceRunning) {
        plSwitch.start();
    }
}
 
開發者ID:vshkl,項目名稱:SaveIg,代碼行數:18,代碼來源:MainActivity.java

示例5: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
    cfg.useGyroscope = false;
    cfg.useCompass = true;
    cfg.useAccelerometer = true;

    // Do the stuff that initialize() would do for you
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    RelativeLayout layout = new RelativeLayout(this);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT);
    layout.setLayoutParams(params);

    AdView admobView = createAdView();
    layout.addView(admobView);
    View gameView = createGameView(cfg);
    layout.addView(gameView);

    setContentView(layout);
    startAdvertising(admobView);
}
 
開發者ID:tgobbens,項目名稱:fluffybalance,代碼行數:32,代碼來源:AndroidLauncher.java

示例6: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mUserLocation = WeatherUtil.getPreferredLocation(this);
    if (findViewById(R.id.weather_detail_container) != null) {
        mIsTwoPane = true;
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.weather_detail_container, new DetailFragment(), DETAILFRAGMENT_TAG)
                    .commit();
        }
    } else {
        mIsTwoPane = false;
        getSupportActionBar().setElevation(8f);
    }
    WeatherForecastFragment forecastFragment = ((WeatherForecastFragment) getSupportFragmentManager()
            .findFragmentById(R.id.fragment_weather_forecast));
    forecastFragment.setUseTodayLayout(!mIsTwoPane);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setLogo(R.mipmap.ic_launcher);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    setTitle();
    Weather4USyncAdapter.initializeSyncAdapter(this);
    MobileAds.initialize(getApplicationContext(), getString(R.string.ad_mob_application_id));
}
 
開發者ID:katamaditya,項目名稱:Weather4U,代碼行數:27,代碼來源:MainActivity.java

示例7: initADs

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
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();
		}
	}
 
開發者ID:GokulNC,項目名稱:USB_Mass_Storage_Enabler,代碼行數:23,代碼來源:MainActivity.java

示例8: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTransition();
    setContentView(R.layout.activity_login);
    // initialize Admob
    MobileAds.initialize(this, AD_UNIT_ID);
    mAuth = getInstance();
    
    boolean flag = SPUtils.getBoolean(this, Constants.USER_CONFIG, Constants.USER_CONFIG_AUTO_LOGIN, false);
    if (!flag) {
        signIn();
    }
    
    startAdFragment();
}
 
開發者ID:Art2Cat,項目名稱:MoonlightNote,代碼行數:17,代碼來源:LoginActivity.java

示例9: onCreateView

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_slash, container, false);
        // initialize Admob
        MobileAds.initialize(mActivity, APP_ID);
        NativeExpressAdView adView = view.findViewById(R.id.adView);
        AdRequest request = new AdRequest.Builder()
//                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
//                .addTestDevice("0ACA1878D607E6C4360F91E0A0379C2F")
//                .addTestDevice("4DA2263EDB49C1F2C00F9D130B823096")
                .build();
        adView.loadAd(request);
        if (!adView.isLoading()) {
            adView.setVisibility(View.GONE);
        }
        return view;
    }
 
開發者ID:Art2Cat,項目名稱:MoonlightNote,代碼行數:20,代碼來源:SlashFragment.java

示例10: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@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);
}
 
開發者ID:peterjosling,項目名稱:scroball,代碼行數:26,代碼來源:ScroballApplication.java

示例11: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

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

    mRefresh = findViewById(R.id.btn_refresh);
    mRequestAppInstallAds = findViewById(R.id.cb_appinstall);
    mRequestContentAds = findViewById(R.id.cb_content);
    mStartVideoAdsMuted = findViewById(R.id.cb_start_muted);
    mVideoStatus = findViewById(R.id.tv_video_status);

    mRefresh.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            refreshAd(mRequestAppInstallAds.isChecked(),
                    mRequestContentAds.isChecked());
        }
    });

    refreshAd(mRequestAppInstallAds.isChecked(),
            mRequestContentAds.isChecked());
}
 
開發者ID:googlesamples,項目名稱:android-ads,代碼行數:26,代碼來源:MainActivity.java

示例12: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");

    // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in
    // values/strings.xml.
    mAdView = 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.
    mAdView.loadAd(adRequest);
}
 
開發者ID:googlesamples,項目名稱:android-ads,代碼行數:23,代碼來源:MyActivity.java

示例13: loadRewardedVideoAd

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
public void loadRewardedVideoAd() {
	if (rewardedVideo == null) {
		//rewardedVideo = new RewardedVideoAd(plugin.getCordova().getActivity());
		rewardedVideo = MobileAds.getRewardedVideoAdInstance(plugin.getCordova().getActivity());
		//
		//rewardedVideo.setAdUnitId(this.rewardedVideoAdUnit);
		rewardedVideo.setRewardedVideoAdListener(new MyRewardedVideoListener());	
	}		
	
	AdRequest.Builder builder = new AdRequest.Builder();
	if(isTest) {
		builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); 
		//builder.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE");				
		String ANDROID_ID = Settings.Secure.getString(plugin.getCordova().getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
		String deviceId = Util.md5(ANDROID_ID).toUpperCase();
		builder.addTestDevice(deviceId);		
	}
	AdRequest request = builder.build();			
	rewardedVideo.loadAd(this.rewardedVideoAdUnit, request);		
}
 
開發者ID:cranberrygame,項目名稱:cordova-plugin-ad-admob,代碼行數:21,代碼來源:AdMobOverlap.java

示例14: onCreate

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MobileAds.initialize(this, "ca-app-pub-3067141613739864~9851773284");

    ((FitbuddyApplication) getApplication()).getComponent().inject(this);

    Fragment workoutListFragment = new WorkoutListFragment();
    getSupportFragmentManager().beginTransaction()
            .add(R.id.fragment_content, workoutListFragment)
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
            .commit();

    bottomNavigation = findViewById(R.id.bottom_navigation);
    bottomNavigation.setOnNavigationItemSelectedListener(this);
}
 
開發者ID:avalax,項目名稱:FitBuddy,代碼行數:18,代碼來源:MainActivity.java

示例15: initAds

import com.google.android.gms.ads.MobileAds; //導入依賴的package包/類
private void initAds() {
    MobileAds.initialize(this, "ca-app-pub-2757743767659351~9555852028");
    //MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713"); // Test


    bigAd = new InterstitialAd(this);
    bigAd.setAdUnitId("ca-app-pub-2757743767659351/2179020563");
    bigAd.loadAd(new AdRequest.Builder().build());

    adTop = findViewById(R.id.adViewTop);
    adBottom = findViewById(R.id.adViewBottom);
    adBottom.loadAd(new AdRequest.Builder().build());
    adTop.loadAd(new AdRequest.Builder().build());
}
 
開發者ID:pontusstjerna,項目名稱:SnakeWear,代碼行數:15,代碼來源:MainActivity.java


注:本文中的com.google.android.gms.ads.MobileAds類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。