本文整理匯總了Java中com.google.android.gms.ads.MobileAds.initialize方法的典型用法代碼示例。如果您正苦於以下問題:Java MobileAds.initialize方法的具體用法?Java MobileAds.initialize怎麽用?Java MobileAds.initialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.android.gms.ads.MobileAds
的用法示例。
在下文中一共展示了MobileAds.initialize方法的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);
}
示例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();
}
}
示例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;
}
示例4: 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));
}
示例5: 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();
}
}
示例6: 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();
}
示例7: 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;
}
示例8: 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);
}
示例9: 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());
}
示例10: 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);
}
示例11: 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);
}
示例12: initializeAds
import com.google.android.gms.ads.MobileAds; //導入方法依賴的package包/類
public static void initializeAds(Context context, AdView adView) {
MobileAds.initialize(context, "ca-app-pub-8963908741443055~4285788324");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("EF67DDDDDDD0896B1B02876D927AC309") // An example device ID
.build();
Log.d("initializeAds: ", adView.getAdUnitId());
adView.loadAd(adRequest);
}
示例13: 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, getString(R.string.appId));
Intent i= new Intent(this, Introduction.class);
this.finish();
this.startActivity(i);
}
示例14: onCreate
import com.google.android.gms.ads.MobileAds; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
String title1 = getString(R.string.title1);
String description1 = getString(R.string.des1);
int img1 = R.drawable.dalai_lama;
int color1 = Color.rgb(92, 107, 192);
String title2 = getString(R.string.title2);
String description2 = getString(R.string.des2);
int img2 = R.drawable.questions;
int color2 = Color.rgb(76, 175, 80);
String title3 = getString(R.string.title3);
String description3 = getString(R.string.des3);
int img3 = R.drawable.wish;
int color3 = Color.rgb(11, 134, 235);
addSlide(AppIntroFragment.newInstance(title1, description1, img1, color1));
addSlide(AppIntroFragment.newInstance(title2, description2, img2, color2));
addSlide(AppIntroFragment.newInstance(title3, description3, img3, color3));
showSkipButton(false);
setProgressButtonEnabled(true);
MobileAds.initialize(this, getString(R.string.appId));
}
示例15: init
import com.google.android.gms.ads.MobileAds; //導入方法依賴的package包/類
public void init (FirebaseApp firebaseApp) {
mFirebaseApp = firebaseApp;
AdMobConfig = FireBase.getConfig().optJSONObject("Ads");
MobileAds.initialize(activity, AdMobConfig.optString("AppId"));
if (AdMobConfig.optBoolean("BannerAd", false)) { createBanner(); }
if (AdMobConfig.optBoolean("InterstitialAd", false)) { createInterstitial(); }
if (AdMobConfig.optBoolean("RewardedVideoAd", false)) {
reward_ads = new HashMap<String, RewardedVideoAd>();
String ad_unit_id = AdMobConfig.optString("RewardedVideoAdId", "");
List<String> ad_units = new ArrayList<String>();
if (ad_unit_id.length() <= 0) {
Utils.d("AdMob:RewardedVideo:UnitId:NotProvided");
ad_units.add(activity.getString(R.string.rewarded_video_ad_unit_id));
} else {
ad_units = Arrays.asList(ad_unit_id.split(","));
Utils.d("AdMob:RewardedVideo:" +
String.valueOf(ad_units.size()) +":UnitIdS:Found");
}
for (String id : ad_units) {
RewardedVideoAd mrv = createRewardedVideo(id);
requestNewRewardedVideo(mrv, id);
reward_ads.put(id, mrv);
}
}
mAdSize = new Dictionary();
mAdSize.put("width", 0);
mAdSize.put("height", 0);
}