Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I. Add Admob
- 1,
- <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" />
- 2, CustomPlayVideo.java
- LinearLayout adview ;
- adview = (LinearLayout) findViewById(R.id.ad);
- adview.setVisibility(View.VISIBLE);
- AdIDManager.addtoParent(adview); //
- //if (MyUtil.isShowAds) {
- //} else {
- // adview.setVisibility(View.GONE);
- //}
- AdIDManager.addtoParent(adview);
- adview = (LinearLayout) findViewById(R.id.llAmobi);
- adview.setVisibility(View.VISIBLE);
- AdIDManager.addtoParent(adview);
- 3, Main Frapment
- import unity2dvn.lib.view.AdIDManager;
- import com.google.android.gms.ads.AdSize;
- private String admobid = "ca-app-pub-4333649515701842/6106828817";
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- initAdmob();
- // Remove
- AdManager.getInstance();
- //AdManager.initAdManager(getActivity(), inmobiKey,
- // BannerView.INMOBI_AD_UNIT_468X60);
- adview = (LinearLayout) view.findViewById(R.id.ad);
- LinearLayout.LayoutParams adWhirlLayoutParams = new LinearLayout.LayoutParams(
- LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- //adview.addView(AdManager.adviewLayout, adWhirlLayoutParams);
- AdManager.setAdview(adview);
- //Them Ham
- private void initAdmob(){
- AdIDManager.getInstance();
- AdIDManager.initAdManager(getActivity(), AdSize.SMART_BANNER, admobid);
- adview = (LinearLayout) view.findViewById(R.id.ad);
- LinearLayout.LayoutParams adWhirlLayoutParams = new LinearLayout.LayoutParams(
- LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- adview.addView(AdIDManager.adviewLayout, adWhirlLayoutParams);
- AdIDManager.setAdview(adview);
- }
- 4. Menu
- showInterstitialAd();
- // new ads
- private InterstitialAd interstitialAd;
- private final static String interstitialKey = "ca-app-pub-9820030150756925/5059024695";//"b99ec229ebcc49ea";
- private void requestAds() {
- interstitialAd.loadAd(new AdRequest.Builder().build());
- }
- private void initInterstitialAds(){
- interstitialAd = new InterstitialAd(getActivity());
- interstitialAd.setAdUnitId(interstitialKey);
- interstitialAd.setAdListener(new AdIDListener(getActivity()){
- @Override
- public void onAdLoaded() {
- // TODO Auto-generated method stub
- super.onAdLoaded();
- Log.e("interstitialAd",
- "onAdLoaded");
- }
- @Override
- public void onAdFailedToLoad(int errorCode) {
- // TODO Auto-generated method stub
- super.onAdFailedToLoad(errorCode);
- requestAds();
- Log.e("interstitialAd",
- "onAdFailedToLoad");
- }
- @Override
- public void onAdOpened() {
- // TODO Auto-generated method stub
- super.onAdOpened();
- Log.e("interstitialAd",
- "onAdOpened");
- }
- @Override
- public void onAdClosed() {
- // TODO Auto-generated method stub
- super.onAdClosed();
- requestAds();
- //showHighscore();
- Log.e("interstitialAd",
- "onAdClosed");
- }
- @Override
- public void onAdLeftApplication() {
- // TODO Auto-generated method stub
- super.onAdLeftApplication();
- Log.e("interstitialAd",
- "onAdLeftApplication");
- }
- });
- requestAds();
- }
- private void showInterstitialAd() {
- if (interstitialAd.isLoaded()) {
- interstitialAd.show();
- }else{
- Log.e("interstitialAd",
- "Interstitial ad was not ready to be shown.");
- //showHighscore();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment