2014-03-29 65 views
3

如何在Android手機差距應用中集成InMobi廣告。我找不到任何關於它的事情。 InMobi有沒有android插件?有沒有人已經實施InMobi Android手機差距應用程序?我想這個代碼,但是這是不工作如何在android phonegap應用中集成inmobi廣告

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

我從我的InMobi。您正在使用的JS API適用於移動網站等,它不是爲phoneGap構建的。話雖如此,你仍然可以在你的phoneGap應用程序中使用它,儘管它對我們來說很難提供相同的支持。 – Sohan

回答

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

此代碼可以在live site上運行。它不適用於phonegap應用程序 –

+1

請參閱此文檔(http://docs.monaca.mobi/en/sampleapp/tips/inmobi/)以獲取關於如何將inmobi集成到混合應用程序。它基於Monaca,但我認爲你對你應該做的事情有足夠的瞭解。 – Tamura

+1

此演示適用於移動網站,不適用於離線,如手機放大器 –

相關問題