gpt4 book ai didi

java - 如何在 Android 应用程序 (sdk 8) 中阻止 InterstitialAd (GMS)

转载 作者:行者123 更新时间:2023-12-01 12:42:08 26 4
gpt4 key购买 nike

我不是程序员,需要你的帮助。我在我的应用程序中使用 Admob (InterstitialAd)。 SDK 8 不支持我的 GMS 库。如何使用 sdk 8 阻止应用程序中的广告。我找到了代码,但不知道如何正确使用它。if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.FROYO)

package com.training;




public class NoAuthorisationMainActivity extends Activity {

......................

private InterstitialAd interstitial;

...............

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


Resources resource = getResources();
Configuration config = resource.getConfiguration();
sharedPreference = PreferenceManager.getDefaultSharedPreferences(this);
if ("ru".equalsIgnoreCase(sharedPreference.getString("language", null))) {
config.locale = RUSSIAN;
} else if ("en".equalsIgnoreCase(sharedPreference.getString("language", null))) {
config.locale = Locale.ENGLISH;

} else if ("es".equalsIgnoreCase(sharedPreference.getString("language", null))) {
config.locale = SPANISH;
}
else {
config.locale = Locale.getDefault();
}
getBaseContext().getResources().updateConfiguration(config, null);

Log.v( "DEBUG", "Main activity starting" );
setContentView(R.layout.main_activity); // ID Activity


Button languageButton = (Button) findViewById(R.id.GoLanguageButton);
languageButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// Intent LanguageButton = new Intent(MainActivity.this, LanguageLocale.class);
// MainActivity.this.startActivity(LanguageButton);
langDialog().show();
}
});





new DBData(this);

// Prepare the Interstitial Ad
interstitial = new InterstitialAd(NoAuthorisationMainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId(MY_AD_UNIT_ID);

AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("6c248b7677c6609d")
.build();

interstitial.loadAd(adRequest);

// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});




findViewById(R.id.noAuthInfo).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent BookButton = new Intent(NoAuthorisationMainActivity.this, WebViewActivity.class);
NoAuthorisationMainActivity.this.startActivity(BookButton);
}
});


findViewById(R.id.noAuthTreker).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent TrackerButton = new Intent(NoAuthorisationMainActivity.this, ShowExercisesListActivity.class);
NoAuthorisationMainActivity.this.startActivity(TrackerButton);
}
});


findViewById(R.id.noAuthInfo2).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(NoAuthorisationMainActivity.this, DnevnikTrenirovokActivity.class);
NoAuthorisationMainActivity.this.startActivity(i);
}
});


findViewById(R.id.noAuthTimer).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent TimerButton = new Intent(NoAuthorisationMainActivity.this, TimerMain.class);
NoAuthorisationMainActivity.this.startActivity(TimerButton);
}
});


findViewById(R.id.noAuthBtnAuth).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(NoAuthorisationMainActivity.this, LoginActivity.class));
}
});


findViewById(R.id.noAuthBtnRegistration).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(NoAuthorisationMainActivity.this, RegisterActivity.class));
}
});








}



private void showMessage(String message)
{
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}

@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
setIntent(intent);

// checkMessage(intent);

setIntent(new Intent());
}

// Create Menu
public boolean onCreateOptionsMenu(Menu menu) // Build menu
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_menu, menu); // ID mainmenu for the menu
return true;
}


// The menus with icons
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) // Set cases if you click on the menu button
{

case R.id.close: // Close WebView
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;
case R.id.google: // Open new WebView with the e.g. Google Url
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://gym-training.com/")));

return true;





default:
return super.onOptionsItemSelected(item);
// You can build more menus and more cases if you like.

}

}

private Dialog langDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.personal_setting);
String[] mas = getResources().getStringArray(R.array.language_sort_options);

final Configuration config = getResources().getConfiguration();

builder.setItems(mas, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 0:
sharedPreference.edit().putString("language", "auto").commit();
config.locale = Locale.getDefault();
break;
case 1:
sharedPreference.edit().putString("language", "en").commit();
config.locale = Locale.ENGLISH;
break;
case 2:
sharedPreference.edit().putString("language", "ru").commit();
config.locale = RUSSIAN;
break;
case 3:
sharedPreference.edit().putString("language", "es").commit();
config.locale = SPANISH;
break;
}

getResources().updateConfiguration(config, null);

Intent intent = new Intent(NoAuthorisationMainActivity.this, NoAuthorisationMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});


return builder.create();
}

@Override
protected void onStart() {
super.onStart();
EasyTracker.getInstance(this).activityStart(this);
}

@Override
protected void onStop() {
super.onStop();
EasyTracker.getInstance(this).activityStop(this);
}

public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {
interstitial.show();
}
}

}

最佳答案

由于很难预测每台设备的状态,因此在访问 Google Play 服务功能而不是 SDK 版本之前,您必须始终检查兼容的 Google Play 服务 APK

要验证 Google Play 服务版本,请调用“isGooglePlayServicesAvailable()”。如果结果代码为 SUCCESS,则 Google Play 服务 APK 是最新的,您可以继续建立连接。但是,如果结果代码为 SERVICE_MISSING、SERVICE_VERSION_UPDATE_REQUIRED 或 SERVICE_DISABLED,则用户需要安装更新。因此,调用 GooglePlayServicesUtil.getErrorDialog() 并向其传递结果错误代码。这会返回一个您应该显示的对话框,其中提供有关错误的适当消息,并提供将用户带到 Google Play 商店安装更新的操作。

关于java - 如何在 Android 应用程序 (sdk 8) 中阻止 InterstitialAd (GMS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24998924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com