3

There is a link which is 5 seconds redirects to another page, how can I make a delay before the redirect Here's an example link: http://s.spynetstation.com/m/Logistics/Logistics%20-%20Medical%20History%20NHSDL09,%202007/05%20Logistics%20-%20Safe%20On%20My%20Side.mp3 Сode

public void ShowTrack(String smetaout,String stitleout){
    AlertDialog.Builder alert = new AlertDialog.Builder(this); 
    alert.setTitle(stitleout);

    WebView wv = new WebView(this);

    wv.setWebViewClient(new WebViewClient() {

        @Override
           public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
             Log.d("My Webview", "shouldOverrideUrlLoading"+urlNewString);
               if (!loadingFinished) {
                  redirect = true;
               }

           loadingFinished = false;
           view.loadUrl(urlNewString);
           Log.d("My Webview", urlNewString);
           return false;
           }

           public void onPageStarted(WebView view, String url) {
               Log.d("My Webview", "onPageStarted"+url);
                loadingFinished = false;

            }

           @Override
           public void onPageFinished(WebView view, String url) {
               if(!redirect){
                  loadingFinished = true;
               }

               if(loadingFinished && !redirect){

               } else{
                  redirect = false; 
               }
               Log.d("My Webview", "onPageFinished"+url);
            }

    });
    wv.loadUrl(smetaout);
    alert.setView(wv);
    alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    alert.show();
}
madcrinkle
  • 71
  • 7

2 Answers2

1

Try this:

public void ShowTrack(String smetaout,String stitleout){
    AlertDialog.Builder alert = new AlertDialog.Builder(this); 
    alert.setTitle(stitleout);

    WebView wv = new WebView(this);

    // Progress dialog starts
    ProgressDialog progressDialog = ProgressDialog.show(YourActivity.this, "", "Loading... ",true ,true);

    wv.setWebViewClient(new WebViewClient() {

       @Override
       public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
           Log.d("My Webview", "shouldOverrideUrlLoading"+urlNewString);
           if (!loadingFinished) {
               redirect = true;
           }

           loadingFinished = false;
           view.loadUrl(urlNewString);
           Log.d("My Webview", urlNewString);
           return false;
       }

       public void onPageStarted(WebView view, String url) {
           Log.d("My Webview", "onPageStarted"+url);
           loadingFinished = false;

       }

       @Override
       public void onPageFinished(WebView view, String url) {

           final Handler handler = new Handler();
           handler.postDelayed(new Runnable() {
               @Override
               public void run() {
                   // Do something after 5s = 5000ms
                   progressDialog.dismiss();
               }
           }, 5000);

           if(!redirect){
              loadingFinished = true;
           }

           if(loadingFinished && !redirect){

           } else{
              redirect = false; 
           }
           Log.d("My Webview", "onPageFinished"+url);
       }

    });
    wv.loadUrl(smetaout);
    alert.setView(wv);
    alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    alert.show();
}

I hope this is what you want.

Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48
  • Unfortunately little is now obtained as follows: the page is requested and immediately worked through the finish line, because the page is blank, I need so the page is requested waits 5 seconds, the redirect and it should load and return to this page already. how this is achieved? – madcrinkle Sep 30 '14 at 08:09
1

Insert any delay (Timer, Async, etc.) before .loadUrl. For example:

new CountDownTimer( 5000, 5000)
 {
   public void onTick( long millisUntilFinished) {}
   public void onFinish()
    {
      view.loadUrl(urlNewString);
    }
 }.start();                  
Tapa Save
  • 4,769
  • 5
  • 32
  • 54
  • Unfortunately little is now obtained as follows: the page is requested and immediately worked through the finish line, because the page is blank, I need so the page is requested waits 5 seconds, the redirect and it should load and return to this page already. how this is achieved? – madcrinkle Sep 30 '14 at 08:14
  • What about @BatuhanC solution with ProgressDialog? – Tapa Save Sep 30 '14 at 08:23
  • he just do it for some reason skips worth log output, but only appears onPageFinish – madcrinkle Sep 30 '14 at 08:41
  • sorry added setJavaScriptEnabled(true); on the page redirect is performed, the page seems to be loaded but for some reason do not see the player itself to run track – madcrinkle Sep 30 '14 at 08:58
  • try add code for enabling plugin: webSettings.setDomStorageEnabled( true); try { webSettings.setPluginState( WebSettings.PluginState.ON); } catch( Exception e) {} try { webSettings.setRenderPriority( RenderPriority.HIGH); } catch( Exception e) {} – Tapa Save Sep 30 '14 at 09:15