收到广告回应Admob错误 [英] There was a getting an ad response Admob Error
问题描述
我想将一个源代码从旧的 GoogleAds SDK
更新到新的 Google Play服务库
,但是有一个问题。每当我遇到此错误时:
I want to update one source code from old GoogleAds SDK
to new Google Play Service Library
, but there is a problem. Everytime I got this error:
获取广告响应时出现问题。
There was a problem getting an ad response.
错误代码:0
ErrorCode: 0
加载广告:0失败
这是来自playactivty的代码:
This is code from playactivty:
public String BANNER_AD_UNIT_ID;
AdRequest adRequest;
private void LoadAds()
{
LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
this.BANNER_AD_UNIT_ID = getResources().getString(R.string.admob_id);
// Create the adView
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(BANNER_AD_UNIT_ID);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
// AdRequest.setTesting(true);
adView.loadAd(adRequest);
}
然后从layout.xml
And from layout.xml
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/admob_id">
</com.google.android.gms.ads.AdView>
<LinearLayout
android:orientation="horizontal"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
我在那里做错了?找不到问题,相信我,我已经阅读了所有关于该错误的SOF帖子:)
What I was doing wrong there? Can not find issue, and trust me, I was read all SOF posts about that error :)
非常感谢!
编辑:
原始代码:
PlayActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
LoadConfigParams();
LoadSharedPreferences();
LoadResources();
LoadListeners();
LoadStage(mCurStage);
LoadAds();
}
private void LoadAds()
{
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayoutAdmob);
// Create the adView
AdView adView = new AdView(this, AdSize.SMART_BANNER, getResources().getString(R.string.admob_id));
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
}
activity_play.xml
(仅最后一个LinearLayout代码,上面是RelativeLayout)。
activity_play.xml
(only last LinearLayout code, above that is RelativeLayout).
<LinearLayout
android:id="@+id/linearLayoutAdmob" android:layout_width="fill_parent"
android:layout_height="wrap_content"></LinearLayout>
推荐答案
通过 java
或 xml创建
Admob
添加的方法有两种/ code>,最简单的方法-(尽管两者都很容易)是 xml
。此外,如果您使用 SMART_BANNER
您将获得不同大小的添加项,如果大小不适合/不匹配剩余的屏幕空间,您的 RelativeLayout
会剩下 LinearLayout
您的添加内容将不会显示。所以我会假设您已经照顾好了
There are two ways of creating an Admob
add by java
or xml
, the easiest way-(even though both are easy) is xml
.Also if you use SMART_BANNER
you are going to get adds of different sizes, and if the size does not fit/match the remaining screen space yourRelativeLayout
has left for LinearLayout
your add will not show. so i will assume you have taken care of that
<LinearLayout
android:id="@+id/linearLayoutAdmob"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.google.android.gms.ads.AdView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
android:id="@+id/myaddview"
ads:adUnitId="@string/admob_id">
</LinearLayout>
然后在您的 loadAds()
AdView adView = findViewById(R.id.myaddview); //add the cast
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);
这就是您需要检查的所有内容此以了解要导入的内容并仔细检查您的权限
thats all you need check this to know what to import and double check your permissions
这篇关于收到广告回应Admob错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!