【发布时间】:2015-12-22 16:35:25
【问题描述】:
我使用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();
}
【问题讨论】:
-
您在运行代码时是否考虑过this? “要在使用 Google Play 服务 SDK 时测试您的应用程序,您必须使用:(1) 运行 Android 2.3 或更高版本并包含 Google Play 商店的兼容 Android 设备。(2) 带有运行 Google 的 AVD 的 Android 模拟器基于 Android 4.2.2 或更高版本的 API 平台。”
标签: java android android-studio admob google-play-services