我目前有幾個應用程序已將admob集成...插頁式廣告加載並顯示應用程序打開時,然後每分鐘顯示另一個廣告....我不知道有什麼問題這是因爲我直接從谷歌獲得我的代碼,並有網上幫助把它放在我的應用程序.....它看起來像它目前設置爲顯示每秒的設置數量......但我最近得到了一個警告admob說插頁式廣告不應該隨機出現或應用程序第一次加載時,他們應該只顯示至少4次點擊或當用戶改變活動後... ...如何正確放置admob插頁式廣告橫幅以避免意外點擊警告?
即時通訊不知道如何實現這在我目前的代碼正確的,因爲我可以在谷歌找到的唯一例子是我目前使用的.....我不想冒險通過錯誤的方式嘗試不同的代碼來禁止我的帳戶... woul d有人能夠解釋和舉例的一個活動,這樣我就可以實現正確是在我的應用程序....
林不知道解決它的最好辦法,但我可以個人認爲解決這一問題的最好辦法將顯示屏幕上顯示「請稍後加載廣告....」,在顯示廣告之前每4次點擊4次並顯示約5秒後出現....用戶關閉廣告後,應用程序將恢復。 ..
或者是更好的活動之間放置廣告,我會如何做到這一點?
有可能是因爲這是一個更好的辦法,但我不知道在所有....任何幫助,將不勝感激
你可以看到谷歌表示,約在這裏實現插頁式廣告 - 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();
}
}
感謝提前任何幫助的建議或例子之一!