如何在android phonegap应用程序中集成inmobi广告

时间:2014-03-29 15:29:11

标签: cordova phonegap-plugins inmobi

如何在Android手机间隙应用中集成InMobi广告。我找不到任何关于它的东西。 InMobi有没有Android插件?有没有人已经实现了InMobi android手机差距应用程序?我试过这段代码,但这不起作用

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

1 个答案:

答案 0 :(得分:1)

您需要inmobi.js并尝试以下代码:

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