Question

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());

       }

});
Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top