2015-12-22 68 views
0

我以前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(); 

} 
+0

你有沒有考慮[這](https://developers.google.com/android/guides/setup)運行代碼時? 「要測試你的應用程序中使用的谷歌Play服務SDK時,您必須使用:(1)兼容的Android設備運行Android 2.3或更高,包括谷歌Play商店(2)與AVD Android模擬器運行的谷歌。基於Android 4.2.2或更高版本的API平臺「。 – gerardnimo

回答

1

。進入SDK管理器和下載Google Play Services,如果你還沒有準備好,Google Play Repository

enter image description here

http://jmsliu.com/2085/add-admob-with-google-play-service.html

那它。除非你安裝這個,否則在Gradle中的那條線就沒有任何意義。要打開SDK管理器:

enter image description here

(envyandroid.com)

讓我知道,如果它在安裝後Google Play Services工作。如果確實如此,請確保接受答案。如果您需要更多幫助,請隨時問我更多問題!

希望它幫助! :-)

+0

嗯,我認爲我已經做到了這一點,因爲插頁式廣告的工作之前,我加入了條幅的。 –