AdMob 没有出现在我的应用程序中?

发布于 2024-12-19 05:39:18 字数 2695 浏览 2 评论 0原文

我有问题,我想将 admob 添加到首选项活动,但应用程序没有显示它。

这是我的 AdMob 活动:

public class AdMobActivity extends Preference {
    public AdMobActivity(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}
    public AdMobActivity(Context context, AttributeSet attrs) {super(context, attrs);}
    public AdMobActivity(Context context) {super(context);}

    @Override
    protected View onCreateView(ViewGroup parent) {
    // this will create the linear layout defined in

    View view = super.onCreateView(parent);

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

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

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

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

    return view;
    }
}

这是我的 AdMob 布局 (banner.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
</LinearLayout>

这是我的偏好活动的 xml:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
        <PreferenceCategory
                android:title="Ads">
             <com.blabla.asafgasf.AdMobActivity android:layout="@layout/banner"/>
        </PreferenceCategory>   
        <PreferenceCategory
        .....
        </PreferenceCategory>
</PreferenceScreen>

我有在project.properties和我的清单中设置target=android-13

<activity android:name=".AdMobActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

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

如果我从应用程序中的configChanges中删除|screenLayout|uiMode|screenSize|smallestScreenSize会出现红框,上面写着: You must have AdActivity statements in AndroidManifest.xml with configChanges.

我已经安装了最新版本的 AdMob 库 (4.3.1) 和最新版本的 SDK (API 14)和最新的ADT插件。 那么问题出在哪里呢?

I have problem I wanna add admob to Preference Activity, but the app doesn't show it.

Here is my AdMob activity:

public class AdMobActivity extends Preference {
    public AdMobActivity(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}
    public AdMobActivity(Context context, AttributeSet attrs) {super(context, attrs);}
    public AdMobActivity(Context context) {super(context);}

    @Override
    protected View onCreateView(ViewGroup parent) {
    // this will create the linear layout defined in

    View view = super.onCreateView(parent);

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

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

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

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

    return view;
    }
}

Here is my layout for AdMob (banner.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
</LinearLayout>

And here is xml for my Preference Activity:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
        <PreferenceCategory
                android:title="Ads">
             <com.blabla.asafgasf.AdMobActivity android:layout="@layout/banner"/>
        </PreferenceCategory>   
        <PreferenceCategory
        .....
        </PreferenceCategory>
</PreferenceScreen>

I have set target=android-13 in project.properties and in my Manifest I have:

<activity android:name=".AdMobActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

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

If I remove |screenLayout|uiMode|screenSize|smallestScreenSize from configChanges in my application will appear red box and there is written: You must have AdActivity declared in AndroidManifest.xml with configChanges.

I have installed the newest version of AdMob library (4.3.1) and the newest version of SDK (API 14) and the newest ADT plugin.
So where is the problem?

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

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

发布评论

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

评论(2

灼疼热情 2024-12-26 05:39:18

您可能没有广告来填充 Admob,您在 LogCat 中收到什么?

You may have no Ads to fill the Admob, what do you receive in LogCat?

菊凝晚露 2024-12-26 05:39:18

我建议您在 hierarchyviewer 工具中检查您的视图。您应该能够看到您的视图是否已添加到 LinearLayout 中。有时会添加视图,但布局参数不正确,因此视图不可见。

您可以在 \tools 中找到该查看器。只需在模拟器中启动您的应用程序,切换到命令提示符/终端并执行可执行文件。

I'd recommend you check your view in hierarchyviewer tool. You should be able to see if your view is being added into your LinearLayout or not. Sometimes a view is added but the layout params are not correct so the view is not visible.

You can find the viewer in \tools. Just launch you app in the emulator switch to the command prompt/terminal and execute the executable.

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