I’m trying to get adwhirl native ads into my app.
I’ve set it up correctly as far as i can tell, and i can see i’m receiving my housead through adwhirl.
But it’s not showing anywhere. the logcat tells me its rotating every 15 seconds as should.
The only error message i see having anything to do with this is : Layout is null!.
so i’m calling ad’s like this in my activity:
LinearLayout layout = (LinearLayout) findViewById(R.id.layout_main);
if (layout == null) {
Log.e("AdWhirl", "Layout is null!");
return;
}
int width = 320;
int height = 72;
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
float density = displayMetrics.density;
width = (int) (width * density);
height = (int) (height * density);
AdWhirlAdapter.setGoogleAdSenseAppName("appname");
AdWhirlAdapter.setGoogleAdSenseCompanyName("companyname");
AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);
AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.adwhirl_layout);
adWhirlLayout.setAdWhirlInterface(this);
AdWhirlLayout adWhirlLayout2 = new AdWhirlLayout(this,"mykey");
adWhirlLayout2.setAdWhirlInterface(this);
adWhirlLayout2.setMaxWidth(width);
adWhirlLayout2.setMaxHeight(height);
RelativeLayout.LayoutParams adWhirlLayoutParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
adWhirlLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.setGravity(Gravity.CENTER_HORIZONTAL);
layout.addView(adWhirlLayout2, adWhirlLayoutParams);
AdWhirlTargeting.setTestMode(true);
TextView textView = new TextView(this);
textView.setText("Below AdWhirlLayout from code");
layout.addView(textView, adWhirlLayoutParams);
layout.setGravity(Gravity.CENTER_HORIZONTAL);
AdWhirlTargeting.setTestMode(true);
adWhirlLayout.addView(adWhirlLayout);
And this is my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.adwhirl"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout_main" >
<com.adwhirl.AdWhirlLayout
android:id="@+id/adwhirl_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Ive googled so much for this, and i’m coming up empty. Anyone have any pointers for me?
As we discussed here, the main reason this wasn’t working was the application was trying to use PhoneGap, which isn’t compatible with AdWhirl.
For any future Android AdWhirl Developers, note that if you have defined an AdWhirlLayout in your manifest:
and you have the AdWhirl Key in your manifest:
then you don’t need to write any additional code. The only things you may want to do are set how long the configuration is valid (this example sets it to 5 minutes) and request test ads during development: