2017-06-12 53 views
0

我已經在我的應用程序中添加了插頁式功能,但效果很好,但問題在於,如果用戶從縱向橫向滑動,廣告再次顯示。顯示因果關係的廣告違反了Google規則。僅在打開的應用程序中顯示Admob Interstital

如何在應用程序打開時設置插頁式廣告? 這是我簡單的代碼廣告暴徒代碼

Admob code image

+0

這種方向變化的情況,重新創建你的活動。你應該處理這種方向變化 –

+1

你的活動應該處理方向變化,而不是admob。在應用開始時也展示插頁式廣告是不允許的做法。請參閱此鏈接https://support.google.com/admob/answer/6201362?hl=zh-CN –

回答

0

您可以創建一個計算廣告多少次顯示的變量。它會是這個樣子:

聲明變量:

int counter = 0;

顯示插播式廣告:

if (counter == 0 && intersitial.isLoaded()) { 
    interstitial.show(); 
    counter++; 
} else { 
    AdRequest interstitialRequest = new AdRequest.Builder().build(); 
    interstitial.loadAd(interstitialRequest); 
} 

在這旁邊,你可以嘗試添加android:configChanges="orientation|screenSize"到您的AndroidManifest.xml。這會阻止您的應用在更改方向時重新啓動。

0

試試這個 -

清單文件 -

(3個參數需要處理方向變化)

android:configChanges="keyboardHidden|orientation|screenSize"> 

活動文件 -

boolean isFirstTimeAdLoading = true; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_rotate); 
     Log.e(TAG, "onCreate()"); 
     if(isFirstTimeAdLoading) 
     { 
      // load ad 
      Log.e(TAG, "Ad Loaded for First Time"); 
      // TODO : Call your Ad Loading Method here 


      // mark ad as 'already loaded once' 
      isFirstTimeAdLoading = false; 
     } 

    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 
     Log.e(TAG, "onStart()"); 
    } 

    @Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 
     Log.e(TAG, "onConfigurationChanged()"); 
     Log.e(TAG, "isFirstTimeAdLoading = " + isFirstTimeAdLoading); 
    } 

日誌 -

06-12 14:44:15.900 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onCreate() 
06-12 14:44:15.900 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: Ad Loaded for First Time 
06-12 14:44:15.900 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onStart() 
06-12 14:44:24.320 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onConfigurationChanged() 
06-12 14:44:24.320 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: isFirstTimeAdLoading = false 
06-12 14:44:26.070 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onConfigurationChanged() 
06-12 14:44:26.070 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: isFirstTimeAdLoading = false 
06-12 14:44:27.880 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onConfigurationChanged() 
06-12 14:44:27.880 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: isFirstTimeAdLoading = false 

如果你看到的日誌,你就會知道,onCreate只調用一次,每次和之後的方向變化,被調用,因此活動不會重新創建每次您旋轉屏幕(我在初始加載後將設備旋轉了三次)。

0

很簡單,你應該不是顯示加入onAdLoaded。這是什麼讓你痛苦。無論您是否轉向橫向瀏覽,它已經違反了Admob政策。

您應該在自己的應用程序的自然中斷點顯示廣告。

+0

嗨,謝謝代碼如何? – user3057363

相關問題