嗨,感謝您的關注!Android webview如何檢測何時重新加載
請問我在我的android應用程序中有一個WebView。
我需要檢測WebView何時重新加載URL。
需要明確的是:當用戶按下網頁上的按鈕,但ID不會更改URL包含在我的WebView網頁重新加載,
因此shouldOverrideUrlLoading
不會被調用。
如何檢測URL重新加載?
這是我的代碼:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preappove);
wait = new ProgressDialog(this);
wait.setTitle("Please Wait");
wait.setMessage("Redirecting to PayPal for your approval");
wait.show();
wv = (WebView) findViewById(R.id.webView);
wv.clearCache(true);
wv.clearHistory();
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
perfs = getSharedPreferences("pefs",
PreApprove.this.MODE_MULTI_PROCESS);
sender = perfs.getString("sender", null);
receiver = perfs.getString("receiver", null);
paymentamount = perfs.getString("paymentamount", null);
maxpaymentamount = perfs.getString("maxpaymentamount", null);
paymentnumber = perfs.getString("paymentnumber", null);
// wv.setWebViewClient(new Callback());
wv.getSettings().setBuiltInZoomControls(true);
GetPreappovalKey gpk = new GetPreappovalKey();
try {
gpk.execute().get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wv.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
wait.dismiss();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("www.google.com")) {
Welcome.fa.finish();
Toast.makeText(PreApprove.this, "Setup Completed Successfully!", Toast.LENGTH_LONG).show();
//PreApprove.this.finish();
Payment.pay(PreApprove.this);
}// GOOD APPROVED
if (url.contains("www.yahoo.com")) {
PreApprove.this.finish();
}// BAD CANCELLED
view.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// NEVER GETS CALLED WHEN PAYPAL RELOADS :-(
}
});
wv.loadUrl("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-preapproval&preapprovalkey="
+ preappovalkey);
}
感謝Daan,我試過了,但是他們沒有檢測到URL重新加載時,它們沒有被加載: - (((( –
當你重新加載時它們會被調用,讓我看看你的其他代碼..) –
添加代碼,請參閱我的編輯,謝謝 –