我使用this实现了我的AdMob横幅,但是我得到了一个错误:W/GooglePlayServicesUtil: Google服务丢失了。
我已经在build.gradle中添加了以下一行:
compile 'com.google.android.gms:play-services-ads:8.4.0'下面是我的onCreate()方法:
保护空洞onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(testBanner);
RelativeLayout layout = new RelativeLayout(this);
layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
//fullscreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//scale image
Display display = getWindowManager().getDefaultDisplay();
size = new Point();
display.getSize(size);
dispX = size.x;
dispY = size.y;
bg = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.bg),dispX,dispY,true);
ls = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.losescreen),GamePanel.rescaleX(805),GamePanel.rescaleY(1105),true);
Pb = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.playbutton),GamePanel.rescaleX(242),GamePanel.rescaleY(242),true);
View gamePanel = new GamePanel(this);
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(gamePanel);
layout.addView(adView, adParams);
mInterstitialAd = new InterstitialAd(this);
setContentView(layout);
contextOfApplication = getApplicationContext();
}发布于 2015-12-22 16:40:58
进入SDK管理器并下载Google Play Services,如果还没有下载,则下载Google Play Repository。

(http://jmsliu.com/2085/add-admob-with-google-play-service.html)
就是这样。在安装此代码之前,gradle中的这一行没有任何意义。要打开SDK管理器:

(envyandroid.com)
安装Google Play Services后,请告诉我它是否工作。如果是的话,一定要接受答案。如果你需要更多的帮助,可以问我更多的问题!
希望它能起作用!
https://stackoverflow.com/questions/34420435
复制相似问题