为什么关闭admob广告后我的对话框没有关闭

时间:2017-05-13 12:20:35

标签: java android dialog admob

我有一个进度对话框,可在应用下载时显示。对话框显示您的应用正在下载,请稍候。下面有一个进度条。它下面还有一个按钮,可以让你看广告..这一切都运行正常,但如果我的应用程序在广告完成之前下载并关闭广告。它会继续在广告开始之前以百分比的形式显示对话框。

我想知道是否有可能在广告显示时隐藏对话框,并且只有在进度未达到100%时才关闭广告

 public class h20_DownloadDialog {

public static final int progress_bar_type = 0;
ProgressDialog pDialog;
private InterstitialAd mInterstitialAd;
Context c;
Firebase mrootRef;


public h20_DownloadDialog(Context context, Firebase mrootRef) {

    this.c = context;
    this.mrootRef = mrootRef;

    mInterstitialAd = new InterstitialAd(context);
    mInterstitialAd.setAdUnitId(context.getString(R.string.comp_ad_unit_id));
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
 onProgressUpdate();
            StartTask();

        }
    });
    final AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();

    mInterstitialAd.loadAd(adRequest);
}



protected Dialog onCreateDialog(int id) {
    switch (id) {
        case progress_bar_type:
            pDialog = new ProgressDialog(c);
            pDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Watch Advert While you wait?", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    showInterstitial();
                   Firebase advertRef = new Firebase("my Firebase ref");
                    Advert_Counter counter = new Advert_Counter(advertRef);
                    counter.count();
                }
            });

            pDialog.setTitle("H20 droid apps");
            pDialog.setMessage("Your app is downloading Please wait...");

            pDialog.setIcon(R.mipmap.ic_launcher);
            pDialog.setIndeterminate(false);
            pDialog.setMax(100);
            pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            pDialog.setCancelable(false);
            pDialog.show();

            return pDialog;
        default:
            return null;
    }
}

private void showInterstitial() {
    // Show the ad if it's ready. Otherwise toast and restart the game.
    if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    } else {
        Toast.makeText(c, "Thanks for choosing H20.", Toast.LENGTH_SHORT).show();
        StartTask();
    }
}

private void StartTask() {
    // Request a new ad if one isn't already loaded, hide the button, and kick off the timer.
    if (!mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded()) {
        AdRequest adRequest = new AdRequest.Builder().build();
        mInterstitialAd.loadAd(adRequest);



        }
    }



}

修改 香港专业教育学院试过这个

protected void onProgressUpdate(String... progress) {
    // setting progress percentage
    pDialog.getProgress();
     if (progress .equals(100)){
         pDialog.dismiss();
     }else {
         pDialog.show();
     }
}

修改 也尝试了这个

protected void onProgressUpdate(String... progress) {
    // setting progress percentage
    pDialog.getProgress();
     if (progress.length<= 100) {
         loadingFinished = false;
     }else{
         loadingFinished = true;
     }
     if (loadingFinished != true){
         pDialog.show();
     }else{
         pDialog.dismiss();
     }

}

0 个答案:

没有答案