Issue
I am trying to get Intent data to the loaded WebView.
Before the intent, There was a EditText, and I originally used the values to login to myURL site with the WebView inside that Activity whitch had userID and userPW (at the site).
But for better design, I've move the Webview to another activity and sends the ID,PW with Bundle.
The problem is that the String variable email and password seems to be set well, but when i try to use the same code i used before, it doesn't work well.
Is there some rules in Android that i can't pass the variables directly without user input?
Does someone know how to solve this problem?
Below is the code i'm currently stuck on
public class MyWeb extends Activity{
WebView webview;
String email;
String password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_myweb);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
email = bundle.getString("ID");
password = bundle.getString("PW");
webview = (WebView)findViewById(R.id.logIn);
webview.setWebViewClient(new WebClient());
webview.getSettings().setDatabaseEnabled(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("myURL");
login(email, password);
}
private void login(String id, String pw){
webview.loadUrl("javascript: {" +
"document.getElementById('userID').value = '"+email +"';" +
"document.getElementById('userPW').value = '"+password+"';" +
"var a = document.getElementsByTagName('input');" +
"a[2].CheckSubmit(); };");
webview.loadUrl("javascript:CheckSubmit()");
}
Solution
webview.setWebViewClient(new WebClient() {
@Override
public void onPageFinished(WebView view, String url) {
webview.loadUrl("javascript: {" +
"document.getElementById('userID').value = '" + email + "';" +
"document.getElementById('userPW').value = '" + password + "';" +
"var a = document.getElementsByTagName('input');" +
"a[2].CheckSubmit(); };");
webview.loadUrl("javascript:CheckSubmit()");
}
});
Solved, I guess it was because of the JS was called before the webpage load thinking that the Activity before this loads all the page while i type in the fields
Answered By - MeromGreen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.