thieumao

add admob in video - anh Thu

Aug 16th, 2014
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. I. Add Admob
  2. 1,
  3. <meta-data
  4. android:name="com.google.android.gms.version"
  5. android:value="@integer/google_play_services_version" />
  6. <activity
  7. android:name="com.google.android.gms.ads.AdActivity"
  8. android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
  9.  
  10. 2, CustomPlayVideo.java
  11.  
  12. LinearLayout adview ;
  13. adview = (LinearLayout) findViewById(R.id.ad);
  14. adview.setVisibility(View.VISIBLE);
  15. AdIDManager.addtoParent(adview); //
  16. //if (MyUtil.isShowAds) {
  17.  
  18. //} else {
  19. // adview.setVisibility(View.GONE);
  20. //}
  21.  
  22. AdIDManager.addtoParent(adview);
  23.  
  24. adview = (LinearLayout) findViewById(R.id.llAmobi);
  25. adview.setVisibility(View.VISIBLE);
  26. AdIDManager.addtoParent(adview);
  27. 3, Main Frapment
  28. import unity2dvn.lib.view.AdIDManager;
  29.  
  30. import com.google.android.gms.ads.AdSize;
  31.  
  32. private String admobid = "ca-app-pub-4333649515701842/6106828817";
  33. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  34. initAdmob();
  35. // Remove
  36. AdManager.getInstance();
  37. //AdManager.initAdManager(getActivity(), inmobiKey,
  38. // BannerView.INMOBI_AD_UNIT_468X60);
  39.  
  40. adview = (LinearLayout) view.findViewById(R.id.ad);
  41. LinearLayout.LayoutParams adWhirlLayoutParams = new LinearLayout.LayoutParams(
  42. LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  43. //adview.addView(AdManager.adviewLayout, adWhirlLayoutParams);
  44. AdManager.setAdview(adview);
  45.  
  46. //Them Ham
  47. private void initAdmob(){
  48. AdIDManager.getInstance();
  49. AdIDManager.initAdManager(getActivity(), AdSize.SMART_BANNER, admobid);
  50. adview = (LinearLayout) view.findViewById(R.id.ad);
  51. LinearLayout.LayoutParams adWhirlLayoutParams = new LinearLayout.LayoutParams(
  52. LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  53. adview.addView(AdIDManager.adviewLayout, adWhirlLayoutParams);
  54. AdIDManager.setAdview(adview);
  55. }
  56. 4. Menu
  57. showInterstitialAd();
  58. // new ads
  59. private InterstitialAd interstitialAd;
  60. private final static String interstitialKey = "ca-app-pub-9820030150756925/5059024695";//"b99ec229ebcc49ea";
  61.  
  62.  
  63. private void requestAds() {
  64. interstitialAd.loadAd(new AdRequest.Builder().build());
  65. }
  66.  
  67. private void initInterstitialAds(){
  68. interstitialAd = new InterstitialAd(getActivity());
  69. interstitialAd.setAdUnitId(interstitialKey);
  70. interstitialAd.setAdListener(new AdIDListener(getActivity()){
  71.  
  72. @Override
  73. public void onAdLoaded() {
  74. // TODO Auto-generated method stub
  75. super.onAdLoaded();
  76. Log.e("interstitialAd",
  77. "onAdLoaded");
  78. }
  79.  
  80. @Override
  81. public void onAdFailedToLoad(int errorCode) {
  82. // TODO Auto-generated method stub
  83. super.onAdFailedToLoad(errorCode);
  84. requestAds();
  85. Log.e("interstitialAd",
  86. "onAdFailedToLoad");
  87. }
  88.  
  89. @Override
  90. public void onAdOpened() {
  91. // TODO Auto-generated method stub
  92. super.onAdOpened();
  93. Log.e("interstitialAd",
  94. "onAdOpened");
  95. }
  96.  
  97. @Override
  98. public void onAdClosed() {
  99. // TODO Auto-generated method stub
  100. super.onAdClosed();
  101. requestAds();
  102. //showHighscore();
  103. Log.e("interstitialAd",
  104. "onAdClosed");
  105. }
  106.  
  107. @Override
  108. public void onAdLeftApplication() {
  109. // TODO Auto-generated method stub
  110. super.onAdLeftApplication();
  111. Log.e("interstitialAd",
  112. "onAdLeftApplication");
  113. }
  114.  
  115.  
  116. });
  117. requestAds();
  118. }
  119.  
  120. private void showInterstitialAd() {
  121. if (interstitialAd.isLoaded()) {
  122. interstitialAd.show();
  123. }else{
  124. Log.e("interstitialAd",
  125. "Interstitial ad was not ready to be shown.");
  126. //showHighscore();
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment