如何在动态壁纸的预览屏幕中放置广告横幅?

发布于 2024-12-05 04:05:53 字数 523 浏览 5 评论 0原文

如萤火虫动态壁纸 (http://www.livewallpapers.org/fireflies-free- 1543/),我不知道如何在预览屏幕(而不是设置屏幕)中放置广告横幅。

附加信息:当我在 Android 2.2.1 上的 HTC 上安装萤火虫壁纸时,横幅会显示在预览和设置屏幕中,但在我的另外两台索尼爱立信(2.3.3 上)上,我只能在设置屏幕。这和索尼爱立信或者安卓版本有关系吗?

谢谢。

PS我确实查看了此链接,但没有找到我的问题的答案:

如何将 admob adview 放入动态壁纸的设置屏幕中?

As in the Fireflies live wallpaper (http://www.livewallpapers.org/fireflies-free-1543/), I don't know how to put an ads banner in the Preview screen (not Settings screen).

Additional info: when I install the Fireflies wallpaper on my HTC which is on Android 2.2.1 the banner shows up in both Preview and Settings screens, but on my two other Sony Ericsson (on 2.3.3) I can only see the banner in the Setting screens. Does that have something to do with Sony Ericsson or the version of Android?

Thank you.

P.S I did look at this link but found no answer to my question:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最好是你 2024-12-12 04:05:53

创建一个新类 AdPreference.java 并包含以下代码:

public class AdPreference extends Preference {

    public AdPreference(Context context, AttributeSet attrs, int defStyle) {super    (context, attrs, defStyle);}
    public AdPreference(Context context, AttributeSet attrs) {super(context, attrs);}
    public AdPreference(Context context) {super(context);}

    @Override
    protected View onCreateView(ViewGroup parent) {
        // this will create the linear layout defined in ads_layout.xml
        View view = super.onCreateView(parent);

        // the context is a PreferenceActivity
        Activity activity = (Activity)getContext();

        // Create the adView
        AdView adView = new AdView(activity, AdSize.BANNER, "YOUR_ADMOB_ID_HERE");

        ((LinearLayout)view).addView(adView);

        // Initiate a generic request to load it with an ad
        AdRequest request = new AdRequest();
        adView.loadAd(request);     

        return view;    
    }
}

在 res/layout 文件夹中创建一个新的 xml 布局,标题为 ad_layout.xml 必须准确。然后包含此代码:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="vertical">  
</LinearLayout>

然后在您的“设置”xml 中的 xmlns 行之后添加此代码:

<com.yourpackagename.AdPreference android:layout="@layout/ad_layout"/>

在您的 AndroidManifest.xml 中添加此代码 也在

<activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

 <meta-data android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" android:value="false" />

您的清单中添加此代码:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

就是这样。它会完美地工作。

Create a new class AdPreference.java and include this code:

public class AdPreference extends Preference {

    public AdPreference(Context context, AttributeSet attrs, int defStyle) {super    (context, attrs, defStyle);}
    public AdPreference(Context context, AttributeSet attrs) {super(context, attrs);}
    public AdPreference(Context context) {super(context);}

    @Override
    protected View onCreateView(ViewGroup parent) {
        // this will create the linear layout defined in ads_layout.xml
        View view = super.onCreateView(parent);

        // the context is a PreferenceActivity
        Activity activity = (Activity)getContext();

        // Create the adView
        AdView adView = new AdView(activity, AdSize.BANNER, "YOUR_ADMOB_ID_HERE");

        ((LinearLayout)view).addView(adView);

        // Initiate a generic request to load it with an ad
        AdRequest request = new AdRequest();
        adView.loadAd(request);     

        return view;    
    }
}

In your res/layout folder create a new xml layout titled ad_layout.xml has to be exact. Then include this code:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="vertical">  
</LinearLayout>

Then in your "settings" xml add this right after the xmlns line:

<com.yourpackagename.AdPreference android:layout="@layout/ad_layout"/>

In your AndroidManifest.xml add this before

<activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

 <meta-data android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" android:value="false" />

Also add this in your manifest:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

And that's it. It'll work perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文