微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

所有活动的 Admob 类我问我如何解决像这段代码这样的旧模型项目

如何解决所有活动的 Admob 类我问我如何解决像这段代码这样的旧模型项目

现在我有一个 wordpress 项目应用程序可以用来处理它,所以这个例子成立于 2018 年。我开始开发。我的情况是代码类 global admob 用于所有活动,因此我发现许多行无法解析。我把问题从 -->// 开始。 请帮我解决这些问题。顺便谢谢你,我的 IDE 版本是 3.5,gradle 是 5.4.1。

package com.exemple.utils;
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.OnPaidEventListener;
import com.google.android.gms.ads.ResponseInfo;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.exemple.R;
public class AdMob  {private static final String TAG = "ADMOB";
    private com.google.android.gms.ads.interstitial.InterstitialAd mInterstitialAd;
    private Context mContext;
    private AdView adView;
    private Handler mHandler;
    private Runnable mHandlerTask;
    private static int INTERVAL = 1000 * 60 * 2;
    public void destroy() {
        stopRepeatingTask();
        mInterstitialAd = null;
        adView = null;
        mHandler = null;
        mHandlerTask = null;
    }
    public AdMob(Context mContext,AdView adView){
     mInterstitialAd = new InterstitialAd(this);//--> InterstitialAd is abstract; cannot be instantiated
        this.mContext = mContext;
        this.adView = adView;
        if (mContext == null){
        }else{
            String interval = mContext.getString(R.string.interval_time);
            if (!TextUtils.isEmpty(interval)){
                try {
                    INTERVAL = Integer.parseInt(interval);
                } catch (Exception ex) {
                    Log.e(TAG,ex.getMessage());
                }
            }
        }
        initInterstitialAd();
        initBannerAds();
    }
 public void initInterstitialAd() {
        assert mContext != null;
        String interstitialId = mContext.getString(R.string.intertatial_ad_id);
        if (!TextUtils.isEmpty(interstitialId)) {
mInterstitialAd.setAdUnitId(interstitialId);//-->Cannot resolve method'setAdUnitId(java.lang.String)'
            mInterstitialAd.loadAd(getAdRequest());//-->Cannot res method'loadAd'
            mInterstitialAd.setAdListener(new AdListener()//->Cannot res method 'setAdListener' {
                public void onAdLoaded() {
                    if (mInterstitialAd != null) {
                        if (mInterstitialAd.isLoaded()//->Cannot res method 'isLoaded') {
                            mInterstitialAd.show();
                        }
                    }
                }
                public void onAdClosed() {
                    mHandler.postDelayed(mHandlerTask,INTERVAL);
                }
            });
        }
    }
public void initBannerAds() {
        if (mContext==null){
        }else {
            MobileAds.initialize(mContext,mContext.getString(R.string.banner_app_id));
            if (adView != null) {
                String bannerId = mContext.getString(R.string.banner_app_id);
                if (!TextUtils.isEmpty(bannerId)) {
                    adView.setVisibility(View.VISIBLE);
               adView.loadAd(getAdRequest());
                } else {
                    adView.setVisibility(View.GONE);
                }
            }}
    }
    public void requestInterstitialAd() {
        if (mInterstitialAd != null) {
            String interstitialId = mContext.getString(R.string.intertatial_ad_id);
            if (!TextUtils.isEmpty(interstitialId)) {
                /* if (SuperViewWeb.isActivityVisible()) {*/
                mInterstitialAd.loadAd(getAdRequest());
                /*} else {*/
                if (mHandler != null) {
                    mHandler.postDelayed(mHandlerTask,INTERVAL);
                }
                /* }*/
            }
        }
    }
    public void requestBannerAds() {
        if (adView != null) {
            if (mContext==null){
            }else {
                String bannerId = mContext.getString(R.string.banner_app_id);
                if (!TextUtils.isEmpty(bannerId)) {
                    adView.loadAd(getAdRequest());
                }
            }
        }
    }
    private AdRequest getAdRequest() {
        return new AdRequest.Builder()
                .addTestDevice(mContext.getString(R.string.banner_app_id))
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();
    }
    public void requestAdMob() {
        mHandler = new Handler();
        requestBannerAds();
        mHandlerTask = new Runnable() {
            @Override
            public void run() {
                requestInterstitialAd();
                requestBannerAds();
            }
        };
        mHandler.postDelayed(mHandlerTask,INTERVAL);
     // mHandlerTask.run();
    }
    public void stopRepeatingTask() {
        if (mHandler != null) {
            mHandler.removeCallbacks(mHandlerTask);
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。