我使用this来实施我的AdMob横幅广告,但是我收到了错误:W / GooglePlayServicesUtil:Google Play服务缺失。
我已将以下行添加到build.gradle
:
compile 'com.google.android.gms:play-services-ads:8.4.0'
这是我的onCreate()
方法:
protected void 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();
}
答案 0 :(得分:1)
进入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
后,请告诉我它是否有效。如果确实如此,请务必接受答案。如果您需要更多帮助,请随时再向我提问!
希望它有所帮助! : - )