【问题标题】:Ads in live wallpaper settings not working动态壁纸设置中的广告不起作用
【发布时间】:2013-11-16 07:15:31
【问题描述】:

我正在尝试在动态壁纸的设置页面中添加广告横幅,但尽管我多次尝试无法添加广告。我遵循了许多教程,但都没有。请告诉我我做错了什么。

我遵循了这个教程

http://irinaramazova.blogspot.in/2011/09/add-admob-adview-to-preferenceactivity.html

我也看到了这个有用的

How do I put an admob adview in the settings screen for a live wallpaper?

两者都不起作用。 我的代码如下

我的 Admobpreference 类

public class AdmobPreference extends Preference
{

public AdmobPreference(Context context) {
    super(context, null);
}

public AdmobPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
protected View onCreateView(ViewGroup parent) {
        //override here to return the admob ad instead of a regular preference display
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    return inflater.inflate(R.layout.admob_preference, null);
}

}

admobpreference.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.djcharon.valentinesday"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent" android:layout_height="fill_parent"
>

<com.google.ads.adview android:id="@+id/adView" android:layout_width="fill_parent" android:layout_height="wrap_content" ads:adunitid="myid" ads:adsize="BANNER"  >      
</com.google.ads.adview>
</LinearLayout>

我的 activity_preference.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

  <com.djcharon.valentinesday.AdmobPreference android:key="adView" />
<CheckBoxPreference android:key="touch" android:title="Enable Touch" android:defaultValue="true"></CheckBoxPreference>


<ListPreference  android:key="kiss" android:title="Wallpaper" android:summary="Select the Wallpaper" android:defaultValue="Background 1" android:entries="@array/listKissSound" android:entryValues="@array/listKissSound" ></ListPreference>
<ListPreference  android:key="heartLife" android:title="Particle life" android:summary="The Particle lifecicle." android:defaultValue="20" android:entries="@array/listLifeCicle" android:entryValues="@array/listLifeCicle" ></ListPreference>

</PreferenceScreen>

我在清单中添加了活动

 <activity android:name="com.google.ads.AdActivity"

          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
     </activity>

我收到一个错误

com.google.ads.adView 膨胀错误

【问题讨论】:

  • 你添加了google ads的jar文件吗?
  • 我添加了 jar 并且我还查看了上面给出的两个链接,说我的是重复的。当我使用上述链接中的建议时,错误消失了,但是当按下设置按钮时我的应用程序崩溃了。
  • 请按照我的示例更改您的 xml 和首选项活动。

标签: android settings admob ads live-wallpaper


【解决方案1】:

现在 Admob 使用 google-playstore service 库。

请参考以下链接。

https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals

【讨论】:

  • 该链接没有用,因为它没有指定如何在不使用活动的情况下严格通过 xml 添加广告视图。
  • @Steve check developers.google.com/mobile-ads-sdk/docs/admob/… with subsection Create your banner in XML
  • 谢谢,但我已经尝试过了。这指定需要存在活动才能使 xml 横幅工作。以前的方法没有。不过,对于像我这样的人来说,在您的应用中使用 google play 服务使得无法将以前的 google ads 库用于以前的方法。与新库冲突。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-04
相关资源
最近更新 更多