[英]How to block InterstitialAd (GMS )in android apps (sdk 8)
Im not programmer and need your help. 我不是程序员,需要您的帮助。 Im using Admob (InterstitialAd) in my app.
我在我的应用中使用Admob(InterstitialAd)。 SDK 8 does not support my GMS library.
SDK 8不支持我的GMS库。 How to block Ad in apps with sdk 8. I found the code but dont know how to use it properly.
如何使用sdk 8阻止应用中的广告。我找到了代码,但不知道如何正确使用它。 if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.FROYO)
如果(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();
}
}
} }
Because it is hard to anticipate the state of each device, you must always check for a compatible Google Play services APK before you access Google Play services features rather than sdk version 由于很难预测每个设备的状态,因此在访问Google Play服务功能而非sdk版本之前,必须始终检查兼容的Google Play服务APK
To verify the Google Play services version, call "isGooglePlayServicesAvailable()". 要验证Google Play服务版本,请调用“ isGooglePlayServicesAvailable()”。 If the result code is SUCCESS, then the Google Play services APK is up-to-date and you can continue to make a connection.
如果结果代码为SUCCESS,则表明Google Play服务APK是最新的,您可以继续建立连接。 If, however, the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED, then the user needs to install an update.
但是,如果结果代码是SERVICE_MISSING,SERVICE_VERSION_UPDATE_REQUIRED或SERVICE_DISABLED,则用户需要安装更新。 So, call GooglePlayServicesUtil.getErrorDialog() and pass it the result error code.
因此,调用GooglePlayServicesUtil.getErrorDialog()并将结果错误代码传递给它。 This returns a Dialog you should show, which provides an appropriate message about the error and provides an action that takes the user to Google Play Store to install the update.
这将返回一个您应该显示的对话框,该对话框提供有关错误的适当消息,并提供将用户带到Google Play商店以安装更新的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.