我将网址加载到WebView
。这是一个登录页面。当用户通过身份验证时,会显示一个页面。我在此时停止加载并开始另一项活动。
点击登录按钮后,用户将被重定向到第一个网址。我现在开始一个进度对话框。在他到达经过身份验证的页面后,我想停止进度对话框并直接想要显示新活动。我不希望用户看到经过身份验证的页面。
现在,“进度”对话框在经过身份验证的页面上停止。用户看到它然后显示下一个活动
有关如何实现这一目标的任何帮助?
这是我的代码: -
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl(url);
final ProgressDialog progressBar = ProgressDialog.show(Details1.this, "Loading..", "Please wait!");
myWebView.setWebViewClient(new WebViewClient()
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
url= view.getUrl();
redirected= Uri.decode(url);
if(redirected!=null &&redirected.contains("Visited"))
{
myprogressDialog= new Utility.ProgressDialogFragment().newInstance();
myprogressDialog.show(getFragmentManager(), "Wait");
}
}
@Override
public void onPageFinished(WebView view, String url)
{
// TODO Auto-generated method stub
super.onPageFinished(view, url);
url= view.getUrl();
redirected= Uri.decode(url);
if(progressBar!=null && progressBar.isShowing())
{
progressBar.dismiss();
}
if(redirected!=null && redirected.startsWith(endpointHost+"/Authorize/index/"+device))//&& myprogressDialog!=null && myprogressDialog.isVisible())
{
myWebView.stopLoading();
myprogressDialog.dismiss();
String authorizationContentString = myurl;
authorizationContentString =authorizationContentString.replace("|", "%7C");
new AuthenticateDevice(Details1.this, Url).execute(authorizationContentString);
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
});
}
private static class ProgressDialogFragment extends DialogFragment
{
public static ProgressDialogFragment newInstance()
{
return new ProgressDialogFragment();
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Translucent);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_dialog_progress, container, false);
}
}
}
答案 0 :(得分:0)
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl(url);
final ProgressDialog progressBar = ProgressDialog.show(Details1.this, "Loading..", "Please wait!");
myWebView.setWebViewClient(new WebViewClient()
{
boolean toStopLoading = false;
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
url= view.getUrl();
redirected= Uri.decode(url);
if(redirected!=null &&redirected.contains("Visited"))
{
myprogressDialog= new Utility.ProgressDialogFragment().newInstance();
myprogressDialog.show(getFragmentManager(), "Wait");
toStopLoading = true;
// start your new activity here.
}
}
@Override
public void onPageFinished(WebView view, String url)
{
// TODO Auto-generated method stub
super.onPageFinished(view, url);
url= view.getUrl();
redirected= Uri.decode(url);
if(progressBar!=null && progressBar.isShowing())
{
progressBar.dismiss();
}
if(toStopLoading){
// finish your web view activity here.
}
if(redirected!=null && redirected.startsWith(endpointHost+"/Authorize/index/"+device))//&& myprogressDialog!=null && myprogressDialog.isVisible())
{
myWebView.stopLoading();
myprogressDialog.dismiss();
String authorizationContentString = myurl;
authorizationContentString =authorizationContentString.replace("|", "%7C");
new AuthenticateDevice(Details1.this, Url).execute(authorizationContentString);
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
});
}
private static class ProgressDialogFragment extends DialogFragment
{
public static ProgressDialogFragment newInstance()
{
return new ProgressDialogFragment();
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Translucent);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_dialog_progress, container, false);
}
}
}
试试这个..