i'm trying to make an app to load and display a webpage on a webview, i want the user has not to login as many times he runs the app so i want to auto fill the fields "username" and "password". I have tried many methods that i found in google but some of them didn't work, the username and password fields stills empty, and the others just opens a blank page with the username value.
Here is part of the code for the web page i'm trying to autolog:
<form action="#" onSubmit="MAIN.doAuth(); return false;"> <div class="user_id"> <label for="user_id">User ID</label> <div class="text_frame"> <input id="user_id" type="text" value="" maxlength="20"> <span class="button_clear_text" onclick=""></span> </div> </div> <div class="password"> <label for="password">Password</label> <div class="text_frame"> <input id="password" type="password" value="" maxlength="20"> <span class="button_clear_text" onclick=""></span> </div> </div> <div class="submit"> <input id="button_login" type="submit" value="LOGIN"> </div> </form>
And here is my mainActivity:
public class FirstScreenActivity<DrawerLayout> extends Activity {
ArrayAdapter adapter;
private DrawerLayout mDrawerLayout;
public String[] names;
public String username = "oscar";
private ListView mDrawerList;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.first_screen);
View header = (View) getLayoutInflater().inflate(R.layout.cabecera, null);
View footer = (View) getLayoutInflater().inflate(R.layout.footer, null);
this.mDrawerList = (ListView) findViewById(R.id.left_drawer); // list view
// Load an array of options names
names = getResources().getStringArray(
R.array.nav_options);
// Set previous array as adapter of the list
/* ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, names);*/
mDrawerList.addHeaderView(header);
mDrawerList.addFooterView(footer);
adapter = new AdaptadorList(
this,
DataSource.TAREAS);
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
WebView webView = (WebView) this.findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setDomStorageEnabled(true);
webView.loadUrl("https://m-komtrax.komatsu.co.jp/m/klc/c/");
//webView.loadUrl("http://www.google.com");
webView.setWebViewClient(new WebViewClient(){
/* @Override
public boolean shouldOverrideUrlLoading(WebView v, String url) {
v.loadUrl(url);
return true;
}*/
@Override
public void onPageFinished(WebView v, String url) {
v.loadUrl("javascript:document.getElementsById('password').value = 'username';");
//v.loadUrl("javascript: document.getElementById('user_id').innerHTML = 'hello';");
//v.loadUrl("javascript:document.querySelector('input[id=user_id]').value = '"+ username +"';");
//v.loadUrl("javascript:document.forms['login'].submit()");
}
});
}
please help me, i need fill the username and password fields with a value that i previous going to store. thanks
I had faced a pretty similar issue.The solution here is just a single line of code to call the super class use super keyword after the onPageFinished method add this line of code.
super.onPageFinished(view, url);
That's it all.Hope it helped Peace!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.