简体   繁体   中英

AdMob: display advertisement in WebView

I use AdMob service to display advertisement in my android app.

I need to display advertisement using WebView instead of opening external web browser for it.

Overriding onLeaveApplication() method in AdListener doesn't help, external application is opened anyways after running method code.

Any solution?

you mean when you click on your ad it opens in a separate browser window? you would like it open inside the same webview?

then you just need to add a shouldoverrideurlloading. something like this:

 public boolean shouldOverrideUrlLoading(WebView view, String url) {



            if( url.startsWith("http:") || url.startsWith("https:") ) {
                 return false;


            }



             // Otherwise allow the OS to handle it
             Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
             startActivity( intent ); 

EDIT: sorry, this is only for the actual webview you are using in your app. since admob ads are displayed in their own little banner (which is essentially a webview too) it doesnt make sense to load that webpage into the banner. therefore a browser window has to pop up. may i ask why that is so important to you? I dont think it can be easily realized, meaning its not really possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM