Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmedia advertisement disappear after clicking item of listview #16

Open
snowuyl opened this issue Oct 1, 2016 · 0 comments
Open

mmedia advertisement disappear after clicking item of listview #16

snowuyl opened this issue Oct 1, 2016 · 0 comments

Comments

@snowuyl
Copy link

snowuyl commented Oct 1, 2016

Dear Floatinghotpot,

     I use cordova-plugin-inappbrowser and your cordova-plugin-mmedia

in my Android project. But the mmedia advertisement disappear when I click item of listview. Do you have any suggestion about this issue. The following is list of my index.html.

<title>Theme Park</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script src="jQueryMobile/jquery.min.js"></script> <script src="jQueryMobile/jquery.mobile.min.js"></script> <script>
    function onLoad() {
        if ((/(ipad|iphone|ipod|android)/i.test(navigator.userAgent))) {
            document.addEventListener('deviceready', initApp, false);
        } else {
            initApp();
        }
    }

    var ad_units = {
        ios : {
            banner : "199321",
            interstitial : "199321"
        },
        android : {
            banner : "199321",
            interstitial : "199321"
        }
    };

    // select the right Ad Id according to platform
    var adid = (/(android)/i.test(navigator.userAgent)) ? ad_units.android : ad_units.ios;

    function initApp() {
        window.open = cordova.InAppBrowser.open;
        //var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');

        if (! mMedia) {
            alert('mMedia plugin not ready');
            return;
        }

        initAd();

        // display the banner at startup
        createSelectedBanner();
    }
    function initAd() {
        var defaultOptions = {
            // adId: adid.banner,
            position : mMedia.AD_POSITION.BOTTOM_CENTER,
            // x: integer,      // valid when set position to 0 / POS_XY
            // y: integer,      // valid when set position to 0 / POS_XY
            // autoShow: true // auto show interstitial ad when loaded, set to false if prepare/show
        };
        mMedia.setOptions(defaultOptions);
        registerAdEvents();
    }
    // optional, in case respond to events or handle error
    function registerAdEvents() {
        document.addEventListener('onBannerFailedToReceive',
                function(data) {
                    alert('error: ' + data.error + ', reason: ' + data.reason);
                });
        document.addEventListener('onBannerReceive', function() {
        });
        document.addEventListener('onBannerPresent', function() {
        });
        document.addEventListener('onBannerLeaveApp', function() {
        });
        document.addEventListener('onBannerDismiss', function() {
        });

        document.addEventListener('onInterstitialFailedToReceive',
                function(data) {
                    alert('error: ' + data.error + ', reason: ' + data.reason);
                });
        document.addEventListener('onInterstitialReceive', function() {
        });
        document.addEventListener('onInterstitialPresent', function() {
        });
        document.addEventListener('onInterstitialLeaveApp', function() {
        });
        document.addEventListener('onInterstitialDismiss', function() {
        });
    }

    function getSelectedPosition() {
        //var i = document.getElementById("adPosition").selectedIndex;
        //var items = document.getElementById("adPosition").options;
        //return parseInt(items[i].value);
        return 8;
    }
    function createSelectedBanner() {
        var overlap = false;
        mMedia.createBanner({
            adId : adid.banner,
            autoShow : true,
            overlap : overlap,
            position : getSelectedPosition()
        }, function() {
        }, function(data) {
            alert(JSON.stringify(data));
        });
    }
    function showBannerAtSelectedPosition() {
        mMedia.showBanner(getSelectedPosition());
    }
    function showBannerAtGivenXY() {
        var x = document.getElementById('x').value;
        var y = document.getElementById('y').value;
        mMedia.showBannerAtXY(x, y);
    }
    function prepareInterstitial() {
        var autoshow = document.getElementById('autoshow').checked;
        mMedia.prepareInterstitial({
            adId : adid.interstitial,
            autoShow : autoshow
        });
    }
    function onResize() {
        var s = document.getElementById('sizeinfo');
        s.innerHTML = "web view: " + window.innerWidth + " x "
                + window.innerHeight;
    }
</script>
<div id="fullpage">

Theme Park

</div>

Thanks in advance!

Best Regards,

snowuyl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant