该应用使用WebView
登录Web应用程序。进入webview后,webview似乎会根据用户的点击次数为您处理所有内容。但是,如果URL更改为特定的注销URL,我需要检查每个事件。
当用户在webview中注销Web应用程序时,如何将用户返回到应用程序本身?我不希望webview保持为活动视图。
我尝试过WebViewClient.shouldOverrideUrlLoading和View.OnTouchListsner。
我试图实施公开课,但它不允许我。
class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
}
以下是我想调用方法来检查URL之前的代码;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText phone = (EditText) findViewById(R.id.phone1);
final EditText login = (EditText) findViewById(R.id.uname);
final EditText pass = (EditText) findViewById(R.id.password);
phone.requestFocus();
final Context context = this;
submit = (Button)findViewById(R.id.submit);
sbutton = (Button)findViewById(R.id.loginCred);
chcred = (CheckBox) findViewById(R.id.cBox);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textstring(phone, login, pass);
encPhone = URLEncoder.encode(Phone);
encLogin = URLEncoder.encode(Login);
encPass = URLEncoder.encode(Pass);
if (chcred.isChecked()) {
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
prefwrite(editor);
}
pushurl();
clear(phone, login, pass);
}
});
WebViewClient() //Right here is where I want to call it
答案 0 :(得分:2)
当网址更改时,事件不会通知您,但会在网页开始加载时通知您,此时您只需要验证当前网址。
答案 1 :(得分:0)
尝试一下 webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
Uri uri = Uri.parse(url);
if (uri.getScheme().contains("google") || uri.getScheme().contains("tel")) {
try {
Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
if (intent.resolveActivity(getPackageManager()) != null)
startActivity(intent);
return true;
} catch (URISyntaxException use) {
Log.e("TAG", use.getMessage());
}
} else {
webview.loadUrl(url);
Log.e("url", url);
}
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
super.doUpdateVisitedHistory(view, url, isReload);
String currentUrl=view.getUrl();
}
});
webView.loadUrl(url);
这里的webView是我的WebView,URL是我在Webview中使用的URL。
如果您想通过url的更改来进行一些更改,那就去
@Override public void doUpdateVisitedHistory(WebView视图,字符串url,布尔值isReload){ super.doUpdateVisitedHistory(view,url,isReload); 字符串currentUrl = view.getUrl();
}
您将在此调用中更新网址。