我目前有一些集成了 admob 的应用程序...插页式广告在应用程序打开时加载并显示,然后每隔一分钟左右显示另一个广告....我不知道这有什么问题,因为我直接从谷歌获得了我的代码,并得到了在线帮助,将其放入我的应用程序中......看起来它目前设置为显示每设定的秒数......但我最近收到了来自 admob 的警告说插页式广告不应随机显示或在应用首次加载时显示,它们应仅在至少 4 次点击后或用户更改活动时显示....
我不确定如何在我当前的代码中正确实现这一点,因为我可以在谷歌上找到的唯一示例是我目前正在使用的示例.....而且我不想冒险通过尝试不同的代码来禁止我的帐户错误的方式......任何人都能够解释并举例说明一项活动,以便我可以在我的应用程序中正确实施......
我不确定修复它的最佳方法,但我个人认为解决此问题的最佳方法是有一个屏幕显示“请等待加载广告....”,每 4 次点击后出现 4 次并显示大约 5 秒在显示广告之前......在用户关闭广告后,应用程序将恢复......
还是在活动之间放置广告更好,我将如何正确地做到这一点?
可能有更好的方法来解决这个问题,但我根本没有任何想法......任何帮助将不胜感激
您可以在此处查看 Google 关于实施插页式广告的说明 - https://support.google.com/admob/answer/6201350?hl=en
这是我的一项活动
public class MainActivity extends TabActivity implements OnTabChangeListener {
TabHost tabHost;
String SearchBaar;
Boolean search_url = false;
String searchurl;
static String about_us;
static SharedPreferences sharedPreferences;
static SharedPreferences.Editor editor;
static int id = 0, id_for_accept = 0, id_for_webview = 0;
private final float LOW_LEVEL = 0.75f;
private final float MEDIUM_LEVEL = 1.0f;
private final float HIGH_LEVEL = 1.5f;
private final float X_HIGH_LEVEL = 2.0f;
private final float XX_HIGH_LEVEL = 3.0f;
float level;
int width;
private InterstitialAd interstitial;
private static final String AD_UNIT_ID_INSERTIAL = "ca-app-pub-4075500144464557/8781418018";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
level = getApplicationContext().getResources().getDisplayMetrics().density;
width = getWindowManager().getDefaultDisplay().getWidth();
main_layout();
}
public void main_layout() {
setContentView(R.layout.tab_bar_main);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
blink();
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
// Get TabHost Refference
tabHost = getTabHost();
tabHost.setOnTabChangedListener(this);
TabHost.TabSpec spec;
Intent intent;
/************* TAB1 ************/
// Create Intents to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, HomePage.class);
spec = tabHost.newTabSpec("Tab1").setIndicator("HOME")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB2 ************/
intent = new Intent().setClass(this, Beats.class);
spec = tabHost.newTabSpec("Tab2").setIndicator("BUY BEATS")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB3 ************/
intent = new Intent().setClass(this, Membership.class);
spec = tabHost.newTabSpec("Tab3").setIndicator("MEMBERSHIP")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB4 ************/
intent = new Intent().setClass(this, Soundkits.class);
spec = tabHost.newTabSpec("Tab4").setIndicator("SOUND KITS")
.setContent(intent);
tabHost.addTab(spec);
if (level <= LOW_LEVEL) {
System.out.println("LEVEL " + level);
// do something here
if (width >= 600 && width < 800) { // it is for 7" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 70;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 70;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 70;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 70;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 70;
// tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 95;
} else if (width >= 800) { // it is for 10" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 80;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 80;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 80;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 80;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 80;
//tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 100;
} else {
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 60;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 60;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 60;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 60;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 60;
//tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 75;
}
} else if (level <= MEDIUM_LEVEL) {
System.out.println("LEVEL " + level);
if (width >= 600 && width < 800) { // it is for 7" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 95;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 95;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 95;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 95;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 95;
//tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 120;
} else if (width >= 800) { // it is for 10" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 100;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 100;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 100;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 100;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 100;
//tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 130;
} else {
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 70;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 70;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 70;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 70;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 70;
//tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 100;
}
// do smoothing here
} else if (level <= HIGH_LEVEL) {
// do something here
if (width >= 600 && width < 800) { // it is for 7" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 105;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 105;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 105;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 105;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 105;
// tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 135;
} else if (width >= 800) { // it is for 10" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 115;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 115;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 115;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 115;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 115;
// tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 145;
} else {
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 90;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 90;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 90;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 90;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 90;
// tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 120;
}
System.out.println("LEVEL " + level);
} else if (level <= X_HIGH_LEVEL) {
if (width >= 600 && width < 800) { // it is for 7" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 140;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 140;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 140;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 140;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 140;
// tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 170;
} else if (width >= 800) { // it is for 10" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 150;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 150;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 150;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 150;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 150;
// tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 180;
} else {
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 100;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 100;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 100;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 100;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 100;
//tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 150;
}
// do something here
System.out.println("LEVEL " + level);
} else if (level <= XX_HIGH_LEVEL || level > XX_HIGH_LEVEL) {
// do something here
if (width >= 600 && width < 800) { // it is for 7" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 170;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 170;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 170;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 170;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 170;
// tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 200;
} else if (width >= 800) { // it is for 10" Tablet
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 190;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 190;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 190;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 190;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 190;
//tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 215;
} else {
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 150;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 150;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 150;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 150;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 150;
//tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 180;
}
System.out.println("LEVEL " + level);
}
TabHost host = (TabHost) findViewById(android.R.id.tabhost);
TabWidget widget = host.getTabWidget();
View v = widget.getChildAt(1);
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(Color.parseColor("#ffffff"));
tv.setTextSize(13);
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View v1 = widget.getChildAt(i);
tabHost.getTabWidget().getChildAt(i)
.setBackgroundColor(Color.parseColor("#424242")); // unselected
TextView tv1 = (TextView) v1.findViewById(android.R.id.title);
// center text
((TextView) tv1).setGravity(Gravity.CENTER);
// wrap text
((TextView) tv1).setSingleLine(false);
tv1.setTextColor(Color.parseColor("#ffffff"));
tv1.setTextSize(13);
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab())
.setBackgroundColor(Color.parseColor("#36ace3")); // selected
}
@Override
public void onTabChanged(String tabId) {
// /************ Called when tab changed *************/
TabHost host = (TabHost) findViewById(android.R.id.tabhost);
TabWidget widget = host.getTabWidget();
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View v = widget.getChildAt(i);
tabHost.getTabWidget().getChildAt(i)
.setBackgroundColor(Color.parseColor("#424242")); // unselected
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(Color.parseColor("#ffffff"));
tv.setTextSize(13);
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab())
.setBackgroundColor(Color.parseColor("#36ace3")); // selected
View v = widget.getChildAt(tabHost.getCurrentTab());
TextView tv = (TextView) v.findViewById(android.R.id.title);
// center text
((TextView) tv).setGravity(Gravity.CENTER);
// wrap text
((TextView) tv).setSingleLine(false);
tv.setTextColor(Color.parseColor("#ffffff"));
tv.setTextSize(13);
}
// public void switchTab(int tab) {
// tabHost.setCurrentTab(tab);
//
// }
private void blink() {
interstitial = new InterstitialAd(MainActivity.this);
interstitial.setAdUnitId(AD_UNIT_ID_INSERTIAL);
//
// // Create ad request.
com.google.android.gms.ads.AdRequest adRequestinsertial = new com.google.android.gms.ads.AdRequest.Builder()
.build();
//
// Begin loading your interstitial.
interstitial.loadAd(adRequestinsertial);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
});
final Handler handler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(120000);
} catch (Exception e) {
}
handler.post(new Runnable() {
@Override
public void run() {
blink();
}
});
}
}).start();
}
}
提前感谢您提供任何帮助建议或示例!