Android WebView login on Android ((plz help)


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. i have built app that display asp pages using WebView but some of the page want the authentication (Username ,Password ) to login I want my application to auto login to this page using Username and Password from my Application
  2.  
  3. This is my code Please Help
  4.  
  5. public class eadvantage extends Activity {
  6. /** Called when the activity is first created. */
  7. WebView mWebView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.eadvantage);
  8.  
  9. HttpClient httpclient = new DefaultHttpClient();
  10. HttpPost httppost = new HttpPost("http://www.ucsi.edu.my/advantage/new/main.asp");
  11.  
  12. try {
  13. // Add your data
  14. List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
  15. nameValuePairs.add(new BasicNameValuePair("txtUserID", "12345));
  16. nameValuePairs.add(new BasicNameValuePair("txtPassword", "12345"));
  17. httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  18.  
  19. // Execute HTTP Post Request
  20. HttpResponse response = httpclient.execute(httppost);
  21.  
  22. mWebView = (WebView) findViewById(R.id.webview);
  23. mWebView.getSettings().setJavaScriptEnabled(true);
  24. mWebView.loadUrl("http://www.ucsi.edu.my/advantage/new/main.asp");
  25.  
  26.  
  27. mWebView.setWebViewClient(new WebViewClient());

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.