Reputation: 99
I used this to implement my AdMob Banners, however I am getting an error: W/GooglePlayServicesUtil﹕ Google Play services is missing.
I have already added the following line to the build.gradle
:
compile 'com.google.android.gms:play-services-ads:8.4.0'
Here is my onCreate()
method:
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();
}
Upvotes: 0
Views: 1600
Reputation: 7561
Go into the SDK manager and download Google Play Services
and, if you haven't already, Google Play Repository
.
(http://jmsliu.com/2085/add-admob-with-google-play-service.html)
Thats it. That line in the gradle signifies nothing until you install this. To open the SDK manager:
(envyandroid.com)
Let me know if it worked after installing the Google Play Services
. If it did, make sure to accept an answer. If you need more help, feel free to ask me any more questions!
Hope it helped! :-)
Upvotes: 2