我以前this實現自己的AdMob橫幅,但我得到一個錯誤:W/GooglePlayServicesUtil:谷歌Play服務的缺失。AdMobs橫幅:W/GooglePlayServicesUtil:谷歌Play服務缺少
我已經添加了以下行build.gradle
:
compile 'com.google.android.gms:play-services-ads:8.4.0'
這裏是我的onCreate()
方法:
保護無效的onCreate(捆綁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();
}
你有沒有考慮[這](https://developers.google.com/android/guides/setup)運行代碼時? 「要測試你的應用程序中使用的谷歌Play服務SDK時,您必須使用:(1)兼容的Android設備運行Android 2.3或更高,包括谷歌Play商店(2)與AVD Android模擬器運行的谷歌。基於Android 4.2.2或更高版本的API平臺「。 – gerardnimo