上周我遇到了一个错误,请更好地帮助我。
我通过RewardedVideo
实现了Admob
,但是却得到了error 3
和一段时间error 0
。当我同时尝试test ads
和{{1}时,这两个错误都面临着我}。
我的代码在下面。
real ads
我对 build.gradle 的依赖是
private RewardedVideoAd mRewardedVideoAd;
Button adsShow;
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, "ca-app-pub-3940256099942544/5224354917");
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
mRewardedVideoAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();
adsShow=(Button)findViewById(R.id.mainidads);
adsShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mRewardedVideoAd.isLoaded()){
mRewardedVideoAd.show();
}
}
});
}
private void loadRewardedVideoAd() {
if(!mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
new AdRequest.Builder().build());
}
}
@Override
public void onRewardedVideoAdLoaded() {
Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdOpened() {
Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdClosed() {
loadRewardedVideoAd();
Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewarded(RewardItem rewardItem) {
Toast.makeText(this, "onRewarded! currency: " + rewardItem.getType() + " amount: " +
rewardItem.getAmount(), Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdLeftApplication() {
Toast.makeText(this, "onRewardedVideoAdLeftApplication",
Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
Toast.makeText(this, "onRewardedVideoAdFailedToLoad "+i, Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoCompleted() {
}
我的日志
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-firestore:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-ads:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-vector-drawable:27.1.1'
implementation 'com.github.bumptech.glide:glide:4.4.0'
implementation 'com.android.support:customtabs:27.1.1'
}
07-31 18:02:14.968 2526-2526 / info.burhanisolution.dholkaapp W / Ads:无法加载广告:3'
请帮助我。
答案 0 :(得分:0)
出现错误的原因之一是您使用添加单元ID而不是应用ID来初始化广告。
// Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
参考-https://developers.google.com/admob/android/quick-start#initialize_mobileads
更改代码以反映位于(Admob控制台-> App-> App设置-> App ID)中的正确app_id
setContentView(R.layout.activity_main);
MobileAds.initialize(this, "ca-app-pub-3940256099942544/5224354917");
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
mRewardedVideoAd.setRewardedVideoAdListener(this);
如果这不能解决您的问题,请使用错误日志更新您的问题