Created
August 24, 2014 16:50
-
-
Save gokhanaliccii/583e00f188ffe0a64a05 to your computer and use it in GitHub Desktop.
Android play service admob integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--layout --> | |
<com.google.android.gms.ads.AdView | |
xmlns:ads="http://schemas.android.com/apk/res-auto" | |
android:id="@+id/adView" | |
android:visibility="gone" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
ads:adSize="BANNER" | |
ads:adUnitId="@string/ad_unit_id" /> | |
<!--layout --> | |
<!-- java code --> | |
AdRequest adRequest = new AdRequest.Builder().build(); | |
Adview adView = (AdView) findViewById(R.id.adView); | |
if (haveAddView()) { | |
adView.loadAd(adRequest); | |
} | |
adView.setAdListener(new AdListener() { | |
@Override | |
public void onAdLoaded() { | |
super.onAdLoaded(); | |
adView.setVisibility(View.VISIBLE); | |
} | |
}); | |
@Override | |
public void onPause() { | |
if (haveAddView()) { | |
adView.pause(); | |
} | |
super.onPause(); | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
if (haveAddView()) { | |
adView.resume(); | |
} | |
} | |
@Override | |
public void onDestroy() { | |
if (haveAddView()) { | |
adView.destroy(); | |
} | |
super.onDestroy(); | |
} | |
private boolean haveAddView() { | |
return adView != null ? true : false; | |
} | |
<!-- java code --> | |
<!--- manifest --> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
<aplication> | |
<meta-data | |
android:name="com.google.android.gms.version" | |
android:value="@integer/google_play_services_version" /> | |
<activity | |
android:name="com.google.android.gms.ads.AdActivity" | |
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> | |
</application | |
<!--- manifest --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment