I'm trying since yersterday afternoon non stop to add a simple banner ad to my app wich is created with phonegap 3.3. Im a beginner in android and I dont know how to make the main layout so that it includes both: the phonegap view and the banner. I followed this tutotial becaus eit describer a more easyer way to add the banner without unsing .xml: https://support.startapp.com/entries/27804376-Adding-a-banner-with-Java-Code-instead-of-XML Right now I see the ad on a black background but the phonegap view isn't showing. How to add the phonegap view too?
mainlayout.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);
}
}
I also tried ti implement the ad the .xml way by addingthis to my main layout:
<com.startapp.android.publish.banner.Banner
android:id="@+id/startAppBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
so my layout is like this:
But it still show me just the add on a black background and the phonegap webview isn't showing.
I tried another way by first implementing the phonegap webview and adding the banner code in the new created layout:
Whatsnap.java: public class WhatSnap extends 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();
}
main.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>
Now the phonegap webview is showing but the ad banner no :(
********EDIT: Im trying for 2 days to implement a simple ad banner into my ap. For that I followed the instructions to implement phonegap as a webview from here: docs.phonegap.com/en/3.3.0/… and I also included the needed banner code into my main layout:
<com.startapp.android.publish.banner.Banner
android:id="@+id/startAppBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
everythings shows up good but after including phonegap as a webview (in the 1 step) the pause and resume events stop working from phonegap and I get these lines in 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 !!!
This is my main activity:
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();
}
this is my layout so far:
<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>
Please help!