【问题标题】:Admob ad not display on real android deviceAdmob 广告不显示在真正的 Android 设备上
【发布时间】:2017-02-07 04:01:21
【问题描述】:

我正在为我的应用使用 admob 广告。我已将默认活动作为 android studio 的 admob 活动,然后我更改了 adunit id。当我在模拟器中运行时,它正在显示广告,但是当我在真实设备中运行相同的代码时,它没有显示任何内容,出现了一个空白屏幕。我正在使用 samsung J7 和 samsung duos 运行 apk。没有任何显示,我搜索了不同的方法,但无法找出问题所在。这是我的代码。 这是我的 xml 文件。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<!-- view for AdMob Banner Ad -->
<com.google.android.gms.ads.AdView

    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"
    />

这里活动类。

public class MainActivity extends AppCompatActivity {
// Remove the below line after defining your own ad unit ID.
private static final String TOAST_TEXT = "Test ads are being shown. "
        + "To show live ads, replace the ad unit ID in res/values/strings.xml with your own ad unit ID.";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Load an ad into the AdMob banner view.
    AdView adView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("ca-app-pub-3940256099942544/6300978111")
            .setRequestAgent("android_studio:ad_template").build();
    adView.loadAd(adRequest);

    // Toasts the test ad message on the screen. Remove this after defining your own ad unit ID.
    Toast.makeText(this, TOAST_TEXT, Toast.LENGTH_LONG).show();
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

显示自定义直播广告需要进行哪些更改。

【问题讨论】:

    标签: android admob ads live


    【解决方案1】:

    问题
    您添加了AdRequest.DEVICE_ID_EMULATOR,因此您可以在模拟器中显示 AdView(banner),但您没有添加到您的真实设备 ID。

    ca-app-pub-3940256099942544/6300978111ad-unit-id 不是设备 ID。

    解决方案
    https://firebase.google.com/docs/admob/android/targeting

    请在链接中添加您的真实设备ID。

    【讨论】:

    • 模拟器和真机的ID不同吗?
    • @UmashankarB 是的,两者的 ID 不同。请记住为每个应该请求测试广告的设备添加一个测试设备 ID。设备 ID 由 Mobile Ads SDK 写入系统日志,因此您可以通过运行您的应用并检查 logcat 来找到您的设备 ID。
    • 直播广告(自定义广告)需要哪个id,我有点困惑
    • 我在 admob 中创建了自己的插件,但我无法在真实设备中显示该广告。展示自己的广告的程序是什么。
    • @UmashankarB 你现在在真实设备上看到测试广告了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多