我正在尝试将adwhirl原生广告投放到我的应用中。 据我所知,我已经正确地设置了它,我可以看到我通过adwhirl接收了我的家伙。 但它并没有在任何地方展示。 logcat告诉我它应该每隔15秒旋转一次。 我看到与此有关的唯一错误消息是:布局为空!。
所以我在我的活动中称广告为:
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);
这是我的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>
我已经用Google搜索了这么多,而且我是空的。有人对我有任何指示?
答案 0 :(得分:0)
您是否已完成setContentView(R.layout.main)
以便了解您的main.xml?
答案 1 :(得分:0)
正如我们讨论的那样here,主要原因是该应用程序试图使用与AdWhirl不兼容的PhoneGap。
对于任何未来的Android AdWhirl开发者,请注意,如果您在清单中定义了AdWhirlLayout:
<com.adwhirl.AdWhirlLayout
android:id="@+id/adwhirl_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
您的清单中有AdWhirl密钥:
<meta-data android:value="643eb700781e4f47b017ea27d1aba3be" android:name="ADWHIRL_KEY" />
然后您不需要编写任何其他代码。您可能想要做的唯一事情是设置配置有效的时间(此示例将其设置为5分钟)并在开发期间请求测试广告:
AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);
AdWhirlTargeting.setTestMode(true);