[英]Do I need to check if the device is connected to the internet to request new interstitial?
我已經在我的應用程序中集成了 Admob 廣告並且我工作正常,但我不知道我是否可以省略檢查設備是否連接到互聯網以請求插頁式廣告的步驟。
這是我的代碼:
//connectiondetec.java:
public class ConnectionDetector {
private Context _context;
public ConnectionDetector(Context context) {
this._context = context;
}
public boolean isConnectingToInternet() {
ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
//noinspection deprecation
NetworkInfo[] info = connectivity.getAllNetworkInfo();
for (NetworkInfo anInfo : info)
if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
return false;
}
}
//Activityone.java:
@Override
protected void onResume() {
super.onResume();
CallNewInertial();
}
private void CallNewInertial() {
ConnectionDetector cd = new ConnectionDetector(Activityone.this);
if (cd.isConnectingToInternet()) {
requestNewInterstitial();
}
}
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(Activityone.this, getString(R.string.interid),
adRequest, new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
mInterstitialAd = interstitialAd;
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
mInterstitialAd = null;
requestNewInterstitial();
}
});
}
那么,我可以刪除連接檢測器 class 以便現在將 CallNewInertial 更改為以下代碼嗎?
private void CallNewInertial() {
requestNewInterstitial();
}
在加載廣告之前檢查互聯網連接並不是一種常見的做法。 加載失敗時重新加載廣告也不是很常見,因為通常在進入下一個屏幕/加載下一個游戲關卡時無論如何都會開始加載新的插頁式廣告。
但是,如果您的應用在請求新廣告時沒有“自然”點,則可以在onAdFailedToLoad
中重新加載它,但將嘗試限制為 3 次,並且可以選擇在下次嘗試之前添加一些延遲。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.