有人能告诉我如何复制用户名吗?密码信息从一个意图到网站,并按下登录按钮


can someone tell me how to copy username & password info from one intent to website and press the login button

这是我要访问的网站与我的应用https://campusvirtual.uclm.es/login/index.php但是,我不想直接这样做。我已经创建了另一个布局,用户将使用它来填写他/她的用户名&密码。问题是代码不能工作。它看起来是这样的:- 这是我想要复制到一个网站的意图代码:

public class MainActivity extends Activity {
private EditText uSer;
private EditText paS;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.cvlogin);
    uSer = (EditText) findViewById(R.id.user);
    paS = (EditText) findViewById(R.id.pass);
    Button web = (Button) findViewById(R.id.button1);
    web.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
             load();
        }  
    }); 
}
protected void load(){ 
    Intent i = new Intent(MainActivity.this, CVLogIn.class ); 
    //create a bundle
    Bundle bundle = new Bundle();
    bundle.putString("user_n",uSer.getText().toString());
    bundle.putString("pass_n",paS.getText().toString());
    // add the intent 
    i.putExtras(bundle);
    startActivity(i);
}   

}

-然后这里是网站,这是我写的代码:

public class CVLogIn extends Activity {
private WebView myWebView;
private String uSer;
private String paS;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.seeweb);
    myWebView = (WebView) findViewById(R.id.webView);

    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // Provide a WebViewClient for your WebView
    myWebView.setWebViewClient(new MyWebViewClient()); 

    // Capturamos el intent creado en MainActivity
            Bundle bundle = this.getIntent().getExtras();
            if (bundle != null){
                myWebView.loadUrl("https://campusvirtual.uclm.es/login/index.php");
                //Recogemos los valores 
                uSer = bundle.getString("user_n");
                paS = bundle.getString("pass_n");
                myWebView.loadUrl("javascript: {" +
                        "document.getElementById('username').value = '"+uSer +"';" +
                        "document.getElementById('password').value = '"+paS+"';" +
                        "var frms = document.getElementsById('loginbtn');" +
                        "frms[0].submit(); };");     
            }
            // ProgressBar
            progressBar = (ProgressBar) findViewById(R.id.progressbar);
            myWebView.setWebChromeClient(new WebChromeClient() 
            {
                @Override
                public void onProgressChanged(WebView view, int progress) 
                {               
                    progressBar.setProgress(0);
                    progressBar.setVisibility(View.VISIBLE);
                    progressBar.incrementProgressBy(progress);
                    if(progress == 100)
                    {
                        progressBar.setVisibility(View.GONE);
                    }
                }
            });
}
@Override
public void onBackPressed() {
    // Check if there's history
    if (this.myWebView.canGoBack())
        this.myWebView.goBack();
    else
        super.onBackPressed();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Check if the key event was the Forward button and if there's history
    if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoForward()) {
        myWebView.goForward();
        return true;
    }
    // If it wasn't the Back key or there's no web page history, bubble up to the default
    // system behavior (probably exit the activity)
    return super.onKeyDown(keyCode, event);
}
private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("campusvirtual.uclm.es")) {
            // This is my web site, so do not override; let my WebView load
            // the page
            return false;
        }
        // Otherwise, the link is not for a page on my site, so launch
        // another Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }
} 

您需要等到第一个loadUrl()加载完成后再调用第二个loadUrl()loadUrl()是异步的,因此当您尝试运行JavaScript时,网页不会加载。尝试在onPageFinished()中执行第二个loadUrl(),看看是否有帮助。

除此之外,在一个普通的Web浏览器中测试你的JavaScript,使用JavaScript控制台(例如,Firebug),看看是否有任何问题。