[英]PhoneGap + Android + AdMob = Network is Unavailable?
在此问题发生后已有3周了。 它在删除了两个第三方插件后开始发生,我认为无论是由于代码延迟还是其他原因,它都在某种程度上帮助了admob的工作。 上周,我从头开始重建了整个项目,并使它运作良好,但是又重新开始了。 我也将开发操作系统从Ubuntu更改为Win8,以防万一,也不能解决问题。
我的感觉是admob SDK正在失去查询网络的功能。 该应用程序本身可以运行,并且需要能够使用互联网。 因此,该应用程序本身具有Internet权限。 如果我要重新启动该应用程序,有时它会工作,有时却无法。 如果我将其置于测试模式,则它应该始终可以工作,但是仍然出现以下错误(以及在此会话期间的后续刷新中):
07-14 12:21:12.600: I/Ads(13271): Request scenario: Offline with no buffered ads.
07-14 12:21:12.600: I/Ads(13271): Network is unavailable. Aborting ad request.
07-14 12:21:12.610: I/Ads(13271): onFailedToReceiveAd(A network error occurred.)
我注意到该网址已在google SDK中进行了修改。 由于某些原因,我裁剪了一些结果,因为其中包含我不想共享的信息。
07-14 12:21:12.175: I/Ads(13271): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script>
07-14 12:21:12.585: I/Ads(13271): Received ad url: <url: "http://googleads.g.doubleclick.net:80/mads/gma?preqs=0&session_id=17668451291953494526
07-14 12:21:12.600: I/Ads(13271): Ad url modified to http://googleads.g.doubleclick.net:80/mads/gma?preqs=0&session_id=17668451291953494526&seq_num=1&u_w=360
我使用的是Admob 6.4.1,但我升级到了6.4.1,因为我在6.3.1中得到了同样的东西。
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
package="com.atomicent.blazereader"
android:versionCode="27"
android:versionName="1.14" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<activity
android:name="com.atomicent.blazereader.BlazeReader"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
活动Java文件:
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
super.appView.getSettings().setJavaScriptEnabled(true);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/index.html");
super.appView.addJavascriptInterface(new Object()
{
@Suppress
public void RateApp()
{
LoadPage(getString(R.string.blazeReaderLink));
return;
}
@Suppress
public void writeLog(String tag, String textBlock)
{
Log.i(tag, textBlock);
return;
}
@Suppress
public void setPageUrl(String url)
{
pageUrl = url;
return;
}
@Suppress
public void refreshPage(String url)
{
mGaTracker.sendView(url);
GAServiceManager.getInstance().dispatch();
return;
}
@Suppress
public void SendException(String exception)
{
mGaTracker.sendException(exception, false);
GAServiceManager.getInstance().dispatch();
return;
}
@Suppress
public void OpenInBrowser()
{
OpenBrowserAction();
return;
}
@Suppress
public void EmailFeedback()
{
SendFeedbackAction();
return;
}
@Suppress
public void RefreshApp()
{
RefreshAction();
return;
}
@Suppress
public void BlazeReaderPro()
{
LoadPage(getString(R.string.blazeReaderProLink));
return;
}
@Suppress
public void OtherAppsLink()
{
LoadPage(getString(R.string.otherAtomicAppsLink));
return;
}
@Suppress
public void BlazeFacebook()
{
BlazeReaderFacebookAction();
return;
}
@Suppress
public void LoadCompleted()
{
//doAdMob();
return;
}
@Suppress
public void shareInterface(String subject, String title, String textBlock)
{
mGaTracker.sendEvent("ui_action", "share", pageUrl, null);
GAServiceManager.getInstance().dispatch();
ShareIntent(getActivity(), subject, title, textBlock, "text/plain");
return;
}
},"MyAndroid");
mGaInstance = GoogleAnalytics.getInstance(this);
mGaTracker = mGaInstance.getTracker(getString(R.string.ga_trackingId));
mHandler.postDelayed(new Runnable() {
public void run() {
doAdMob();
}
}, 5000);
}
protected void doAdMob()
{
// Create the adView
AdSize adSize;
String screenType = getString(R.string.screen_type);
if(screenType.equals("1"))
{
adSize = AdSize.BANNER;
}
else if(screenType.equals("2"))
{
adSize = AdSize.IAB_BANNER;
}
else if(screenType.equals("3"))
{
adSize = AdSize.IAB_LEADERBOARD;
}
else
{
adSize = AdSize.BANNER;
}
AdView adView = new AdView(this, adSize, "pubID");
LinearLayout layout = super.root;
layout.addView(adView);
AdRequest request = new AdRequest();
request.addTestDevice("B00EF0D66CFCBE408653D4FFE7DF8C2A");
request.addTestDevice("9B556DEC8E1B587D9DE1910F4D8ECFDC");
adView.loadAd(request);
adView.setAdListener(this);
}
在代码AdView中,我删除了pubID以便在此处发布它。 非常需要一些帮助。 这是怎么回事? 有人遇到这个问题吗? 我已经在stackoverflow和其他地方阅读了有关此内容的每篇文章,但没有任何文章有用。 我还清理了几次项目。 是否有某些设置可能会阻止admob能够查询网络?
我了解到问题是由于config.xml文件不正确。 无论出于什么原因,它都不再与我拥有的项目兼容。 我用作admob 100%工作基础的项目没有config.xml文件,因此没有任何冲突(至少从admob的角度来看)。
经过15次重新测试和0次失败,我相信这是正确的解决方案。 config.xml文件应显示为:
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.origin.packagename"
versionCode="27"
version = "1.14">
<!-- versionCode is optional and Android only -->
<name>App Name</name>
<description>
An example for phonegap build docs.
</description>
<author href="http://www.url.com" email="email.com">
Author Name
</author>
<preference name="phonegap-version" value="2.9.0" />
<preference name="target-device" value="universal" />
<preference name="permissions" value="none"/>
<!-- to enable individual permissions use the following examples -->
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/notification"/>
<access origin="*" />
</widget>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.