1. Download our Official Android App: Forums for Android!

Place Admob Interstitial to avoid violation

Discussion in 'Android Development' started by nyt1972, Sep 20, 2017.

  1. nyt1972

    nyt1972 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Sep 20, 2017

    Sep 20, 2017
    3
    0
    5
    Hello,

    I am working on JoanZapata PDF viewer and wanted to place interstitial ad on my app but wanted to avoid admob violation issue, below is the code pls help me.

    below is my code:

    Code (Java):
    1. @EActivity(R.layout.activity_main)
    2. @OptionsMenu(R.menu.actionbar)
    3. public class PDFViewActivity extends SherlockActivity implements OnPageChangeListener, View.OnClickListener {
    4.  
    5.     public static final String SAMPLE_FILE = "mybook.pdf";
    6.  
    7.     public static final String KEY_BOOKMARKS = "bookmarks_pages";
    8.  
    9.     @ViewById
    10.     PDFView pdfView;
    11.  
    12.     @NonConfigurationInstance
    13.     String pdfName = SAMPLE_FILE;
    14.  
    15.     @NonConfigurationInstance
    16.     Integer pageNumber = 1;
    17.  
    18.     SharedPreferences sharedpreferences;
    19.     public static final String mypreference = "mypref";
    20.     public static final String Name = "nameKey";
    21.     public static final String Email = "emailKey";
    22.  
    23.     Spinner bookmarkSp;
    24.     ArrayAdapter<String> dataAdapter;
    25.     private final int TotalPages = 57;
    26.  
    27.     private AdView mAdView;
    28.  
    29.     private String TAG = PDFViewActivity.class.getSimpleName();
    30.     InterstitialAd mInterstitialAd;
    31.  
    32.     @AfterViews
    33.     void afterViews() {
    34.         sharedpreferences = getSharedPreferences(mypreference,
    35.                 Context.MODE_PRIVATE);
    36.         display(pdfName, false);
    37.     }
    38.  
    39.     /*@OptionsItem
    40.     public void about() {
    41.         if (!displaying(ABOUT_FILE))
    42.             display(ABOUT_FILE, true);
    43.         <item
    44.         android:id="@+id/about"
    45.         android:icon="@drawable/ic_about"
    46.         android:title="About"
    47.         android:showAsAction="ifRoom|withText" />
    48.     }*/
    49.  
    50.     int check = 0;
    51.  
    52.     private void display(String assetFileName, boolean jumpToFirstPage) {
    53.  
    54.         if (jumpToFirstPage) pageNumber = 1;
    55.  
    56.         mAdView = (AdView) findViewById(R.id.adView);
    57.         AdRequest adRequest = new AdRequest.Builder()
    58.                 .build();
    59.         mAdView.loadAd(adRequest);
    60.  
    61.         mInterstitialAd = new InterstitialAd(this);
    62.  
    63.         // set the ad unit ID
    64.         mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
    65.  
    66.         AdRequest adRequest1 = new AdRequest.Builder()
    67.                 .build();
    68.  
    69.         // Load ads into Interstitial Ads
    70.         mInterstitialAd.loadAd(adRequest1);
    71.  
    72.         mInterstitialAd.setAdListener(new AdListener() {
    73.             public void onAdLoaded() {
    74.                 showInterstitial();
    75.             }
    76.         });
    77.  
    78.         int x = TotalPages;
    79.         int[] page_seq = new int[TotalPages];
    80.         for (int i = 0; i < TotalPages; i++) {
    81.             page_seq[i] = --x;
    82.             Log.d("testdesp", "" + page_seq[i]);
    83.         }
    84. //        .pages(2,1,0)
    85.  
    86.         pdfView.fromAsset(assetFileName)
    87.                 .defaultPage(TotalPages)
    88.                 .pages(page_seq)
    89.                 .onLoad(new OnLoadCompleteListener() {
    90.                     @Override
    91.                     public void loadComplete(int nbPages) {
    92.                         ((TextView) findViewById(R.id.tv_total_page)).setText("/ " + pdfView.getPageCount());
    93.                     }
    94.                 })
    95.                 .onPageChange(this)
    96.                 .load();
    97.    }
    98.  
    99.     private void showInterstitial() {
    100.         if (mInterstitialAd.isLoaded()) {
    101.             mInterstitialAd.show();
    102.         }
    103.     }
    104.  
    105.  
    106.     @Override
    107.     public void onPageChanged(int page, int pageCount) {
    108.         pageNumber = page;
    109.         ((EditText) findViewById(R.id.et_page_number)).setText(pageCount - (pageNumber - 1) + "");
    110.         if (check(page))
    111.             ((TextView) findViewById(R.id.tv_add_bookmark)).setText("Remove bookmark");
    112.         else
    113.             ((TextView) findViewById(R.id.tv_add_bookmark)).setText("Add to bookmark");
    114.    
    115.     }
    116.  
    117.     @Override
    118.     public void onBackPressed() {
    119.         super.onBackPressed();
    120.     }
    121.  
    122.     private boolean displaying(String fileName) {
    123.         return fileName.equals(pdfName);
    124.     }
    125.  
    126.    
    127. }
     

    Advertisement

Share This Page

Loading...