3

How to integrate InMobi ads in android phone gap app. I can't find anything about it. Is there any android plugin for InMobi? Did anyone already implement InMobi android phone gap app? I tried this code but this is not working

var userIP = "115.246.164.46";
var useragent = "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";
$.ajax({
    url: "http://api.w.inmobi.com/showad/v2",
    type: 'POST',
    contentType: "application/json charset=utf-8",
    data: {
        "responseformat": "axml",
        "imp": [{
            "ads": 1,
            "adtype": "int",
            "banner": {
                "adsize": 14,
                "pos": "top",
                "api": 1
            }
        }],
        "site": {
            "id": "e702096c879446f39755da0e81b1d5c5"
        },
        "device": {
            "ip": userIP,
            "ua": useragent
        }
    },
    success: function(d) {
        alert(d);
    },
    error: function(request, status, error) {
        alert(error);
    }
});
Yushox
  • 162
  • 12
Prithvi Raj Nandiwal
  • 3,122
  • 3
  • 22
  • 34
  • I'm from InMobi. The JS API that you are using is for mobile websites and the like and it isn't built for phoneGap. That being said, you can still use it in your phoneGap application although its tough for us to provide support for the same. – Sohan Apr 08 '14 at 10:44

1 Answers1

1

You need inmobi.js and try the code below:

  var inmobi_conf =
  {
    siteid : "4028cba631d63df10131e1d3191d00cb", // your Property ID
    slot: 15,
    test: true,
    manual: true,
    autoRefresh: 60,
    targetWindow : "_blank",
    onError : function(code)
    {
      if(code == "nfr")
      {
        console.log("Error getting the ads!");
      }
    }
  };

  document.addEventListener("deviceready", onDeviceReady, false);

  function onDeviceReady()
  {
    console.log('device ready');
    $.getScript("inmobi.js", function(){
      showAds();
    });
  }

  function showAds()
  {
    var adsElement = document.getElementById('the id of the DOM element for displaying the ads'); 
    _inmobi.getNewAd(adsElement);
  }
Tamura
  • 1,788
  • 1
  • 14
  • 10
  • 1
    Please refer to this (http://docs.monaca.mobi/en/sampleapp/tips/inmobi/) for a complete tutorial on how to integrate inmobi in a hybrid app. It is based on Monaca but I think you get enough idea of what you should do. – Tamura Apr 01 '14 at 10:35
  • 1
    this demo for mobile website not for offline like phonegap – Prithvi Raj Nandiwal Apr 01 '14 at 12:40
  • 4
    If you have an OFFLINE app, you'll receive no ads from no ad networks. ever. – Akshaya Shanbhogue Apr 07 '14 at 11:18
  • Can it not be structured in such a manner that the app gets ads when the phone has an active internet connection and degrades gracefully if the phone is offline? – Vinayak Aug 26 '15 at 09:10