广告 Admob Interstitial + 加载页面 Activity 打开应用程序后 |在 Android Studio 4.2.2 Jelly Bean 中

Ads Admob Interstitial + Loading Page Activity After Open App | in Android Studio 4.2.2 Jelly Bean

如何在我的项目(版本 4.2.2 Jelly Bean)中添加插页式 admob? Admob 在应用程序 运行 和应用程序关闭时出现。

我想要上图或 google 推荐的插页式 admob 逻辑。 知道的请帮帮我... 知道的请帮帮我...

这是我的项目代码:Home.java

public class Pro extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private static final int PICKFILE_REQUEST_CODE = 1;

public ValueCallback<Uri[]> mFilePathCallback;

// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;

private OnFragmentInteractionListener mListener;

public Pro() {
    // Required empty public constructor
}

/**
 * Use this factory method to create a new instance of
 * this fragment using the provided parameters.
 *
 * @param param1 Parameter 1.
 * @param param2 Parameter 2.
 * @return A new instance of fragment Home.
 */
// TODO: Rename and change types and number of parameters
public static Pro newInstance(String param1, String param2) {
    Pro fragment = new Pro();
    Bundle args = new Bundle();
    args.putString(ARG_PARAM1, param1);
    args.putString(ARG_PARAM2, param2);
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        mParam1 = getArguments().getString(ARG_PARAM1);
        mParam2 = getArguments().getString(ARG_PARAM2);
    }
}



// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
    if (mListener != null) {
        mListener.onFragmentInteraction(uri);
    }
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (context instanceof OnFragmentInteractionListener) {
        mListener = (OnFragmentInteractionListener) context;
    } else {
        throw new RuntimeException(context.toString()
                + " must implement OnFragmentInteractionListener");
    }
}

@Override
public void onDetach() {
    super.onDetach();
    mListener = null;
}

/**
 * This interface must be implemented by activities that contain this
 * fragment to allow an interaction in this fragment to be communicated
 * to the activity and potentially other fragments contained in that
 * activity.
 * <p>
 * See the Android Training lesson <a href=
 * "http://developer.android.com/training/basics/fragments/communicating.html"
 * >Communicating with Other Fragments</a> for more information.
 */
public interface OnFragmentInteractionListener {
    // TODO: Update argument type and name
    void onFragmentInteraction(Uri uri);
}

private View mContentView;

private Handler handler = new Handler(){
    @Override
    public void handleMessage(Message message) {
        switch (message.what) {
            case 1:{
                webViewGoBack();
            }break;
        }
    }
};




public static Pro newInstance() {
    Pro fragment = new Pro();
    return fragment;
}

private WebView webView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){
    View v = inflater.inflate(R.layout.fragment_pro, parent, false);

    webView = (WebView) v.findViewById(R.id.webPage);
    webView.setWebChromeClient(new WebChromeClient());

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    Uri data = Uri.parse("http://192.168.1.104/safa/pro");
    webView.loadUrl(data.toString());

    webView.setOnKeyListener(new View.OnKeyListener(){
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK
                    && event.getAction() == MotionEvent.ACTION_UP
                    && webView.canGoBack()) {
                handler.sendEmptyMessage(1);
                return true;
            }

            return false;
        }

    });
    webView.setWebChromeClient(new WebChromeClient() {


        @Override
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
            mFilePathCallback = filePathCallback;
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("*/*");
            startActivityForResult(intent, PICKFILE_REQUEST_CODE);
            return true;
        }
    });

    webView.setWebViewClient(new WebViewClient(){
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("sms:") || url.startsWith("tel:") || url.startsWith("mailto:")
                    || url.startsWith("bbmi://") || url.startsWith("whatsapp://")
                    || url.startsWith("https://www.google.co.id/maps/") || url.startsWith("https://www.youtube.com")
                    || url.startsWith("https://www.facebook.com/") || url.startsWith("https://twitter.com/")
                    || url.startsWith("https://play.google.com/") || url.startsWith("https://mail.google.com/")


                    )  {
                view.getContext().startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            } else {
                return false;
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            webView.loadUrl("file:///android_asset/404.html");

        }
    });
    return v;
}

public boolean canGoBack() {
    return this.webView != null && this.webView.canGoBack();
}

public void goBack() {
    if(this.webView != null) {
        this.webView.goBack();
    }
}
private void webViewGoBack(){
    webView.goBack();
}



@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == PICKFILE_REQUEST_CODE) {
        //Uri result = intent.getData();
        Uri result = intent == null || resultCode != RESULT_OK ? null
                : intent.getData();
        if(result != null){
            Uri[] resultsArray = new Uri[1];
            resultsArray[0] = result;
            mFilePathCallback.onReceiveValue(resultsArray);
        }
        else
            mFilePathCallback.onReceiveValue(null);

    }
}

}

试试这个,很简单。它的工作方式与您想要的相同...

public class Home extends Activity {

private InterstitialAd interstitialAd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    // Prepare the Interstitial Ad
   interstitialAd = new InterstitialAd(Home.this);
   interstitialAd.setAdUnitId(getString(R.string.interstitial_unit_id));
   AdRequest adRequest = new AdRequest.Builder().build();
   interstitialAd.loadAd(adRequest);
   interstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            if (interstitialAd.isLoaded()) {
                interstitialAd.show();
            }
        }
    });


    /* do your other code here */
 }
}

更多信息请访问here