Implement interstitial ads in the App

Asked

Viewed 120 times

0

Can anyone explain to me in a brief tutorial on how to implement, interstitial Admob ads in my app which is a simple browser.

The problem is that it keeps giving wrong classes, as I have no experience in java, I can’t implement correctly. I need help.

I’m trying to implement, from this example: tutorial

My code:

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (isOnline()) {
    Toast.makeText(getApplicationContext(), "Carregando", Toast.LENGTH_SHORT).show();

    //mWebView = (WebView) findViewById(R.id.webview);

    mWebView = (WebView) findViewById(R.id.webview);
    Uri uri = Uri.parse("http://xxxx.xx");//Link por defeito
    Intent intent = getIntent();
    if(intent.getAction() == Intent.ACTION_VIEW){
        uri = intent.getData();
    }
    mWebView.loadUrl(uri.toString());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setSupportZoom(false);
    mWebView.setWebViewClient(new LinkWebViewClient());
    mWebView.requestFocusFromTouch();
    mWebView.setWebChromeClient(new WebChromeClient());
    }
else
[...]
}
private class LinkWebViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
    if(isOnline()) {
        Toast.makeText(getApplicationContext(), "Loading", Toast.LENGTH_SHORT).show();
        webview.loadUrl(url);
        return true;
    }
    else
    {
        Toast.makeText(getApplicationContext(), "Sem conexão", Toast.LENGTH_SHORT).show();
        setContentView(R.layout.conexaofail);
        return false;
    }
}
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {

if((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack())
{
    if (isOnline()) {
        mWebView.goBack();
        return true;
    }
    else
    {
        setContentView(R.layout.conexaofail);
        return false;
    }
}
return super.onKeyDown(keyCode, event);
 }

Can someone help me? I ask you to have a little patience with me because I am a beginner and I want to learn.

  • Your code suggests that your application runs on a webview, there is no ad code there. You took a look at the firebase git, it’s pretty simple to implement the interstical ad. [https://github.com/googleads/googleads-mobile-android-examples/blob/master/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java]

  • Error 404 on your link!

  • 1

    [Link Git][1] [1]: https://github.com/googleads/googleads-mobile-android-examples/tree/master/admob/InterstitialExample

  • Get it! Thank you very much!

  • 1

    Great, glad I could help.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.