【问题标题】:InterstitialAd in specified activity指定活动中的插页式广告
【发布时间】:2018-10-27 13:05:47
【问题描述】:

我从事这项活动 请告诉我 如何在将用户重定向到 Google Play 商店之前显示插页式广告?

有可能吗?

 public class MyClinet extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        if (Uri.parse(url).getHost().equals("myhostsite")) {
            return false;
        }
        if (Uri.parse(url).getScheme().equals("market")) {
            try {

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                Activity host = (Activity) view.getContext();
                host.startActivity(intent);
                return true;
            } catch (ActivityNotFoundException e) {
                // Google Play app is not installed, you may want to open the app store link
                Uri uri = Uri.parse(url);
                view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
                return false;
            }

        }
        return false;
    }
}

【问题讨论】:

    标签: java android webview


    【解决方案1】:

    只要按照这个谷歌官方教程,你就会实现你想要的https://developers.google.com/admob/android/interstitial

    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
    

    但核心是在您的插页式广告中添加一个监听器,并在广告关闭时重定向用户。像这样:

    mInterstitialAd.setAdListener(new AdListener() {
    
        @Override
        public void onAdClosed() {
            // Your redirect code goes here
        }
    });
    

    【讨论】:

    • 好的,谢谢@André Sousa,我希望它能如我所愿。
    • 你添加加载了吗?
    • 如果是这种情况并且没有显示广告,那么您的日志中应该有与广告 API 相关的错误。
    • 我可以像脸书或推特一样私下和你谈谈吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多