我找到了解决方案。我把一个alertdialog通过网站的原始登录。 之后,我将Java脚本代码注入到URL中,该URL填写网站上的表单,然后自动提交。 如果有人有兴趣,我这样做是这样的:
AlertDialog为登录:
private void logIn() {
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.activity_login, null);
final EditText username = (EditText) textEntryView.findViewById(R.id.username);
final EditText password = (EditText) textEntryView.findViewById(R.id.password);
username.setText("", TextView.BufferType.EDITABLE);
password.setText("", TextView.BufferType.EDITABLE);
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(Html.fromHtml("<font color='#ffffff'>Login</font>"));
alert.setView(textEntryView);
alert.setPositiveButton("Login",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
User = username.getText().toString();
Pw = password.getText().toString();
autoFillIn();
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
alert.show();
}
然后autoFillIn:
public void autoFillIn(){
mWebview.getSettings().setJavaScriptEnabled(true);
mWebview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:document.getElementById('LoginForm_username').value = '" + User + "';document.getElementById('LoginForm_password').value='" + Pw + "';document.forms[0].submit();");
}
});
mWebview .loadUrl(frontendurl);
setContentView(mWebview);
}
希望这可以帮助别人。 而我始终是敞开的更好的想法..
编辑: “frontendurl”是我想通过web视图中显示的URL字符串..
来源
2014-11-26 07:58:29
3k1