In my application I have an activity which acts as log-in form. After getting user id and password, i need to open a URL.
This web page includes log-in form (user id and password fields as well) and when user clicks on submit button, form processed by java-script function and form contents will be submitted to server.
However, I need to bypass showing this page and instead, loading URL, putting user id and password into parameters and calling doSubmit() function of JavaScript on behalf of user and finally getting server response.
I have user id and password but i don’t know how to insert it into JavaScript.
This is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_loginweb);
Log.i(TAG, "Try to create activity...");
WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl(LOGINPAGE_URL);
webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
}
}
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
any suggestion would be appreciated. Thanks
On your Javascript interface add some methods like this :
From javascript side :