您好我正在使用android的phonegap应用程序。我在浏览admob脚本时遇到问题,因为它没有显示任何广告。我想我在清单中拥有所有权限:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.mauriziopz.disegna"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".DisegnaActivity"
android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|screenLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是我的测试页面,它不起作用
<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>
<script type="text/javascript">
var admob_vars = {
pubid: 'MY_ID', // publisher id
test: true, // test mode, set to false if non-test mode
manual_mode: true
};
</script>
<script type="text/javascript" src="http://mmv.admob.com/static/iphone/iadmob.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
var a = _admob.fetchAd(document.getElementById('admob_ad'));
}
</script>
</head>
<body>
<div id="container">
Test
<div id='admob_ad'></div>
</div>
</body>
</html>
我在手动模式下尝试过但没有尝试,但从未能让它工作。 有任何想法吗? 感谢
答案 0 :(得分:2)
我不是这方面的专家,但我认为你必须执行你的var a。
function onDeviceReady() {
var a = _admob.fetchAd(document.getElementById('admob_ad'));
//trigger the var
a;
}
and add body onLoad to execute
<body onLoad="onDeviceReady()">
它在这里工作,像这样:
<body onLoad="doIt()">
<div id="admob_ad"></div>
<script type="text/javascript">
function doIt() {
_admob.fetchAd(document.getElementById('admob_ad'));
//document.addEventListener("deviceready", onDeviceReady, false);
}
</script>
答案 1 :(得分:0)
@MaurizioPz:您需要在Admob的Android清单文件中添加一个活动,如下所示:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
另请确保您使用的是最新的Admob SDK。