I need to log in and post user Id and pass word into the web view. Can anyone help me, please!!! thanks in advance.
How to show needed content in a webview. I need to get required contents in a webview to post login data
public class MainActivity extends AppCompatActivity {
EditText login_user,login_password;
Button login_button;
String uName,uPwd,data;
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login_user=(EditText)findViewById(R.id.userName);
login_password=(EditText)findViewById(R.id.passWord);
login_button=(Button)findViewById(R.id.loginButton);
webView=(WebView)findViewById(R.id.webView);
login_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
getText();
}catch(Exception e){
e.printStackTrace();
}
}
});
}
private void getText() {
uName = login_user.getText().toString();
uPwd = login_password.getText().toString();
WebView webview = new WebView(this);
setContentView(webview);
String url = "website url";
String postData = null;
try {
postData = "username=" + URLEncoder.encode(uName, "UTF-8") + "&password=" + URLEncoder.encode(uPwd, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
webview.postUrl(url,postData.getBytes());
}
}