Android: Need Mopub Ad to Open in WebView when clicked on

﹥>﹥吖頭↗ 提交于 2019-12-06 11:16:50

问题


I am curious how to load a webview when clicking on a mopub ad. By default the ad is opening a browser. There is very little documentation on this and I haven't been able to find any examples.

I instantiate the AdView class that I found in the mopub api as it seems like it should do what I want but to no avail. And I'm still not sure how to switch the ad click from browser to webview.

Also, getClickThroughUrl() returns null. Mopub is storing the url though because the page opens in a browser. So how do I properly retrieve the URL?

Here's my code:

mAdView.setAdUnitId(MOPUB_SALES_LIST_ID);
mAdView.loadAd();

mAdView.setOnAdLoadedListener(new OnAdLoadedListener() {
       public void OnAdLoaded(MoPubView mpv) {
          adPopupLayout.setVisibility(View.VISIBLE);
    }
});

mAdView.setOnAdClickedListener(new OnAdClickedListener() {
    @Override
    public void OnAdClicked(MoPubView m) {
        AdView adview = new AdView(getApplicationContext(), mAdView);
        adview.loadUrl(m.getClickthroughUrl());

       }

});

回答1:


This is not very easy. You will have to make changes in the mopub SDK.

In the AdView class, you need to change the showBrowserForUrl() to load a webview instead of browser.




回答2:


Since you have the URL that you need to go to. You could probably make yourself a WebView and call its load method passing along the URL, instead of calling load on the adview, which is probably just sending out the URL as an ACTION_VIEW intent, and the browser is set to listen for these when the content is a URL. If you install a 3rd party browser (firefox, opera, dolphin etc) and when you click the ad if you are given a list of options that includes all of the browsers installed you could verify that it is using the intent that way.



来源:https://stackoverflow.com/questions/9041219/android-need-mopub-ad-to-open-in-webview-when-clicked-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!