Google Admob Android:仅在一台设备上运行 [英] Google Admob Android: Working on only one device
问题描述
我已经在我的android应用中设置了admob adview:清单:
I have set up an admob adview in my android app: The manifest:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-123456567787889990">
我的xml:
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-0987784576567456234511"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent">
</com.google.android.gms.ads.AdView>
在我的Java代码中,我完成了以下操作:
In my java code I have done the following:
MobileAds.initialize(this, "ca-app-pub-123456567787889990");
AdRequest adRequest = null;
if (BuildConfig.DEBUG) {
adRequest = new AdRequest.Builder().addTestDevice("EDDADA7CC97DD3A4AAD9123312312321").build();
} else {
adRequest = new AdRequest.Builder().build();
}
adView.loadAd(adRequest);
我了解到,真正的广告只能在生产中使用,而我必须使用测试广告.但是,测试广告仅出现在一台设备(我正在测试的设备)上,并且该设备可以在该设备上正常运行.但是,它不会出现在任何其他设备上.我向我的客户发送了一个APK,广告空间始终显示为空白,没有test-ad.
I understand that real ads are only to be used in production and I have to use test ads. However the test ads appear only on the one device(the device that I am testing on), its working properly there. However it does not appear on any other device. I sent an apk to my client and the ad-space always appears blank with no test-ad.
这是故意的行为还是我错过了一些东西?请帮忙.
Is this the intented behavior or am I missing something?? Please help.
推荐答案
在调试模式下,您仅为 adRequest()
添加了一个测试设备.因此,它仅适用于该设备.首先,您不需要使用具有真实AdMob单元ID的真实帐户进行测试,就可以使用测试广告单元ID.而且不需要检查它是否处于调试模式.
You have added only one test device for adRequest()
in debug mode. So it's working for that device only. First of all, you don't need to test with a live account with real AdMob unit id, you can use test ad unit id. And don't need to check if it is in debug mode or not.
您可以按照这种方式来集成AdMob测试横幅广告.
You can follow this way to integrate AdMob test banner ads.
- 将其添加到项目级别的build.gradle
allprojects {
repositories {
google()
jcenter()
}
}
- 添加此应用级的build.gradle
dependencies {
implementation 'com.google.android.gms:play-services-ads:17.1.1'
}
-
然后将其添加到应用程序标记内的Manifest.xml文件中
Then add this in Manifest.xml file inside application tag
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="[ADMOB_APP_ID]"/>
4.然后在您布置xml文件
4.Then In you layout xml file
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
- 然后在您的活动中执行此操作
package ...
import ...
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this,
"ca-app-pub-3940256099942544~3347511713");
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
}
然后它将在所有设备上完美运行.之后,您只需替换admob应用ID和横幅广告单元ID.希望对您有帮助.
Then it will work perfectly for all devices. After that you have to just replace your admob app id and banner unit id. Hope it will help you.
这篇关于Google Admob Android:仅在一台设备上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!