我正在开发一款使用AdMob的Android应用。我正在加载横幅广告和插页式广告。我无法加载加载。我一直在logcat中获得相同的错误模式,但无法弄清楚如何更新以解决错误。我将把我的xml和java文件与我的logcat一起包含在内。我搜索过上一篇文章,看到类似的东西,但它没有得到解决。
爪哇:
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
public class MainActivity extends AppCompatActivity {
private InterstitialAd mInterstitialAd;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(getApplicationContext(), "ca-app-pub-8163174299019987/4501487157");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-8163174299019987/4442611559");
AdRequest intadRequest = new AdRequest.Builder()
.addTestDevice("YOUR_DEVICE_HASH")
.build();
mInterstitialAd.loadAd(intadRequest);
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
startActivity(new Intent(MainActivity.this, Game.class));
}
});
}
}
XML
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-8163174299019987/4501487157"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>
Logcat
06-17 10:59:42.750 20745-20745/com.marijuanastrainquiz I/Ads: Starting ad request.
06-17 10:59:42.801 20745-20745/com.marijuanastrainquiz W/GooglePlayServicesUtil: Google Play services out of date. Requires 9080000 but found 8489470
06-17 10:59:42.957 20745-20745/com.marijuanastrainquiz W/art: Verification of void com.google.android.gms.ads.internal.zzl.zzbO() took 103.363ms
06-17 10:59:43.008 20745-20755/com.marijuanastrainquiz I/art: Background sticky concurrent mark sweep GC freed 10140(1841KB) AllocSpace objects, 64(1912KB) LOS objects, 16% free, 8MB/10MB, paused 544us total 207.601ms
06-17 10:59:43.008 20745-20745/com.marijuanastrainquiz I/Ads: Starting ad request.
06-17 10:59:43.090 20745-20853/com.marijuanastrainquiz W/GooglePlayServicesUtil: Google Play services out of date. Requires 9080000 but found 8489470
06-17 10:59:43.090 20745-20853/com.marijuanastrainquiz W/Ads: Failed to connect to remote ad request service.
06-17 10:59:43.090 20745-20853/com.marijuanastrainquiz W/Ads: Could not start the ad request service.
06-17 10:59:43.094 20745-20809/com.marijuanastrainquiz W/GooglePlayServicesUtil: Google Play services out of date. Requires 9080000 but found 8489470
06-17 10:59:43.094 20745-20809/com.marijuanastrainquiz W/Ads: Failed to connect to remote ad request service.
06-17 10:59:43.094 20745-20809/com.marijuanastrainquiz W/Ads: Could not start the ad request service.
06-17 10:59:43.122 20745-20745/com.marijuanastrainquiz W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
06-17 10:59:43.123 20745-20745/com.marijuanastrainquiz W/Ads: Failed to load ad: 0
06-17 10:59:43.123 20745-20745/com.marijuanastrainquiz W/Ads: Failed to load ad: 0
答案 0 :(得分:0)
首先,您需要查看手机的Google Play服务版本。
您没有将设备哈希。
AdRequest intadRequest = new AdRequest.Builder()
.addTestDevice("YOUR_DEVICE_HASH")
.build();
在这里,您需要将YOUR_DEVICE_HASH替换为您的设备ID才能开始获取测试广告。
希望它会有所帮助:)