我从昨天下午开始不停地尝试向我的应用程序添加一个简单的横幅广告,该应用程序是使用 phonegap 3.3 创建的。我是 android 的初学者,我不知道如何制作主要布局,以便它包括:phonegap 视图和横幅。我遵循了这个教程,因为它描述了一种更简单的方法来添加横幅而无需取消 .xml: https: //support.startapp.com/entries/27804376-Adding-a-banner-with-Java-Code-instead-of- XML 现在我在黑色背景上看到广告,但没有显示 phonegap 视图。如何也添加phonegap视图?
主布局.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/
</RelativeLayout>
whatsnap.java:
public class WhatSnap extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
StartAppSDK.init(this, "id", "id");
// StartAppAd.showSplash(this, savedInstanceState);
// StartAppAd.showSlider(this);
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
appView.addJavascriptInterface(this, "WhatSnap");
//super.loadUrl("file:///android_asset/www/index.html")
setContentView(R.layout.mainlayout);
// Get the Main relative layout of the entire activity
RelativeLayout mainlayout = (RelativeLayout)findViewById(R.id.mainlayout);
// Define StartApp Banner
Banner startAppBanner = new Banner(this);
RelativeLayout.LayoutParams bannerParameters =
new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
bannerParameters.addRule(RelativeLayout.CENTER_HORIZONTAL);
bannerParameters.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
// Add to main Layout
mainlayout.addView(startAppBanner, bannerParameters);
}
}
我还尝试通过将这个添加到我的主布局中来以 .xml 方式实现广告:
<com.startapp.android.publish.banner.Banner
android:id="@+id/startAppBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
所以我的布局是这样的:
但它仍然只显示黑色背景上的添加,并且没有显示 phonegap webview。
我尝试了另一种方法,首先实现 phonegap webview 并在新创建的布局中添加横幅代码:
Whatsnap.java:公共类 WhatSnap 扩展 CordovaActivity
{
CordovaWebView cwv;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cwv = (CordovaWebView) findViewById(R.id.tutorialView);
Config.init(this);
StartAppSDK.init(this, "id", "id");
super.loadUrl(Config.getStartUrl());
appView.addJavascriptInterface(this, "WhatSnap");
}
}
@Override
public ExecutorService getThreadPool() {
return getThreadPool();
}
主.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:baselineAligned="false"
tools:context=".MainActivity" >
<org.apache.cordova.CordovaWebView
android:id="@+id/tutorialView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.startapp.android.publish.banner.Banner
android:id="@+id/startAppBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
现在 phonegap webview 正在显示,但广告横幅没有:(
********编辑:我尝试了 2 天在我的应用程序中实施一个简单的广告横幅。为此,我按照以下说明将 phonegap 实现为 webview:docs.phonegap.com/en/3.3.0/...,我还将所需的横幅代码包含在我的主布局中:
<com.startapp.android.publish.banner.Banner
android:id="@+id/startAppBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
一切都显示得很好,但是在将 phonegap 包含为 web 视图(在第 1 步中)之后,暂停和恢复事件停止从 phonegap 工作,我在 logcat 中得到这些行:
07-10 12:10:10.368: D/CordovaActivity(20511): Paused the application!
07-10 12:10:10.368: D/CordovaWebView(20511): Handle the pause
07-10 12:10:10.378: D/CordovaLog(20511): null: Line 1 : exception firing resume event from native
07-10 12:10:10.378: I/Web Console(20511): exception firing resume event from native at null:1
07-10 12:10:10.383: D/CordovaLog(20511): null: Line 1 : exception firing pause event from native
07-10 12:10:10.383: I/Web Console(20511): exception firing pause event from native at null:1
07-10 12:10:10.483: E/JavaBinder(20511): !!! FAILED BINDER TRANSACTION !!!
这是我的主要活动:
public class WhatSnap extends CordovaActivity
{
CordovaWebView cwv;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
StartAppSDK.init(this, "id", "id");
appView.addJavascriptInterface(this, "WhatSnap");
setContentView(R.layout.main);
cwv = (CordovaWebView) findViewById(R.id.tutorialView);
Config.init(this);
cwv.loadUrl(Config.getStartUrl());
}
@Override
public ExecutorService getThreadPool() {
return getThreadPool();
}
到目前为止,这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<org.apache.cordova.CordovaWebView
android:id="@+id/tutorialView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.startapp.android.publish.banner.Banner
android:id="@+id/startAppBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
请帮忙!