【问题标题】:Admob Ads doesn't work on real deviceAdmob 广告无法在真实设备上运行
【发布时间】:2014-11-30 17:36:21
【问题描述】:

我试图使用新的 google-service-libs 在我的应用中设置 admob 广告。并且在 genymotion 模拟器广告中看起来一切都很好。但他们不在真正的设备上,比如我的带有 android 2.3.6 的 Galaxy ace gt5830i。我不知道是什么问题。

这里有一些代码:

XML:

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

    <LinearLayout
        android:id="@+id/titleBar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@drawable/title_bar"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/iconImg"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:layout_margin="5dip"
            android:background="@drawable/app_icon" />

        <ImageView
            android:id="@+id/titleImg"
            android:layout_width="160dp"
            android:layout_height="45dp"
            android:layout_gravity="center"
            android:layout_margin="5dip"
            android:background="@drawable/title" />

        <RelativeLayout
            android:id="@+id/pagerBtn"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingRight="2dip" >

            <ImageButton
                android:id="@+id/pager"
                android:layout_width="45dp"
                android:layout_height="35dp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:background="@drawable/button_clicked"
                android:scaleType="fitXY"
                android:src="@drawable/pager" />
        </RelativeLayout>
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="5dip"
        android:background="@drawable/shadow" >
    </View>

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        ads:adSize="BANNER"
        ads:adUnitId="@string/adUnitId" />

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/buttons"
        android:divider="#351802"
        android:dividerHeight="2dp"
        android:listSelector="@drawable/list_selector" />

</LinearLayout>

我的 Ad_Unit_Id 保存在 res/ 文件夹中的 string.xml 文件中。

java:

AdView ad = (AdView) findViewById(R.id.adView);

        AdRequest req = new AdRequest.Builder().build();

        ad.loadAd(req);

如果您需要更多代码,请告诉我。谢谢

【问题讨论】:

  • 检查横幅的分辨率以及 AdView 上的填充。我猜 AdView 的大小是 320 x 50 dip .. 另外,检查你的 logcat
  • 好的,我会检查并回复谢谢。
  • 发布您的 logcat,它会告诉您为什么没有收到广告。可能很简单,因为您的设备没有可用的广告。

标签: android admob google-play-services


【解决方案1】:

我之前遇到过这个问题,因为广告横幅需要比手机分辨率更大的分辨率。

因此,水平测试应用程序,一旦完成,您将能够看到完整的广告。

【讨论】:

  • 好的,我会横向尝试。我会回复的。感谢回复
【解决方案2】:

尝试根据设备的屏幕分辨率动态定义广告的adsize:

 AdSize adSize = AdSize.SMART_BANNER;  

    DisplayMetrics dm = getResources().getDisplayMetrics();  
    double density = dm.density * 160;
    double x = Math.pow(dm.widthPixels / density, 2);
    double y = Math.pow(dm.heightPixels / density, 2);
    double screenInches = Math.sqrt(x + y);   
    if (screenInches > 8) { // > 728 X 90
        adSize = AdSize.LEADERBOARD;
    } else if (screenInches > 6) { // > 468 X 60
        adSize = AdSize.MEDIUM_RECTANGLE;
    } else { // > 320 X 50
        adSize = AdSize.BANNER;
    }

    ad = (AdView) findViewById(R.id.adView);
     adView.setAdSize(adSize);
    AdRequest adRequest = new AdRequest.Builder().build();
     adView.loadAd(adRequest);

【讨论】:

    猜你喜欢
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多