【问题标题】:Admob Ads is not showing upAdmob 广告未显示
【发布时间】:2013-12-07 12:33:05
【问题描述】:

好的,我来这里之前做了很多研究(对不起我的英语)。

我的问题是:我制作了一个应用程序并实现了 Admob 4.3.1(我的应用程序是在 Android 3.2(使用 eclipse)上开发的。

我第一次遇到错误“您必须具有 INTERNET 和 ACCESS_NETWORK_STATE 权限,我将它们放在我的 AndroidManifest.xml 中,现在一切正常,但是当我启动我的应用程序时,我的广告没有显示。

希望你能尽快帮助我...非常感谢。

这是我的 AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.package.sound"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:icon="@drawable/gg"
    android:label="@string/app_name" >
    <activity
        android:name=".testpackagesound"
        android:label="@string/app_name" >
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
    <activity
        android:name=".test1"
        android:label="@string/app_name" >
        </activity>
    <activity
        android:name=".test2"
        android:label="@string/app_name" >
        </activity>
    <activity
        android:name=".test3"
        android:label="@string/app_name">
        </activity>
        <meta-data android:value="xxxxxxxxxxxx" android:name="ADMOB_PUBLISHER_ID" />
        <uses-sdk android:minSdkVersion="7" />
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/image"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >


<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="test1"
    android:textColor="#005113" />


<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="test2"
    android:textColor="#970000" />





<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="test3"
    android:textColor="#001760" />

</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="50dip" >

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    ads:adSize="BANNER"
    ads:adUnitId="xxxxxxxxxx"
    ads:loadAdOnCreate="true" >
</com.google.ads.AdView>


</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true" >
<LinearLayout 
android:layout_width="300px"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
>
<Button
android:id="@+id/button4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test4" />
   <Button
android:id="@+id/button18"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test18" />

</LinearLayout>
</ScrollView>
</LinearLayout>

【问题讨论】:

  • 代码看起来没问题;我不认为 SDK 使用 ADMOB_PUBLISHER_ID,但这不应该有任何影响。检查 logcat 输出,看看 SDK 给你什么样的消息。

标签: java android admob ads


【解决方案1】:

所以基本上我唯一能想到的就是你错过了 layout.xml 文件中的某些内容。以下是一些可能对您有所帮助的示例:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
   //............Some other views
<com.google.ads.AdView android:id="@+id/adView"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_centerInParent="true"
                       ads:adUnitId="Your Add ID"
                       ads:adSize="BANNER" 
                       ads:loadAdOnCreate="true"/>
   //Some other views

如果我没记错的话,你要么忘记了第 3 行,要么没有正确的添加 ID。希望对您有所帮助。

如果这对您没有帮助,请查看 official android addmob documentationhere

还希望您将 AddMob 库导入到您的项目中。

【讨论】:

  • 还是不行,我可以把我的布局发给你吗?因为我是新会员,所以不能在这里发帖。
  • 好的,只需在您的问题上单击编辑并将其放在最后就更容易了。
  • 完成了。非常感谢...我正在尝试从 4 天开始找到解决此问题的方法...
  • 检查是否导入了admob库。此外,您似乎有此行的副本 xmlns:android="schemas.android.com/apk/res/android" xmlns:ads="schemas.android.com/apk/lib/com.google.ads" 将它们保留在您的基础中,首先是线性布局。
  • 我的问题已解决....我在我的应用程序上看不到我自己的广告,因为我的手机已获得 Root 权限/ROM 已刷新...
【解决方案2】:

如果布局中没有足够的空间,广告将不会展示。检查 logcat 日志以获取任何和所有与广告相关的消息。如果是这种情况,请参阅此Admob ads not showing - Android 以获取建议。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多