Guest User

Untitled

a guest
Jan 9th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public void loginPost(View view){
  2. String username = usernameField.getText().toString();
  3. String password = passwordField.getText().toString();
  4.  
  5.  
  6. try{
  7.  
  8.  
  9. String link="http://mwssong.esy.es/android/Login.php";
  10. String data = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(username, "UTF-8");
  11. data += "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8");
  12.  
  13. URL url = new URL(link);
  14. URLConnection conn = url.openConnection();
  15.  
  16. conn.setDoOutput(true);
  17. OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  18.  
  19. wr.write( data );
  20. wr.flush();
  21.  
  22. BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  23.  
  24. StringBuilder sb = new StringBuilder();
  25. String line = null;
  26.  
  27. // Read Server Response
  28. while((line = reader.readLine()) != null)
  29. {
  30. sb.append(line);
  31. break;
  32. }
  33.  
  34. if(sb.toString()=="admin")
  35. new AdminScreen();
  36. else if(sb.toString()=="Customer")
  37. {
  38.  
  39. Intent myIntent(view.getContext(),AdminScreen.class);
  40. startActivity(myIntent);
  41. }
  42. else
  43. status.setText(sb);
  44. }
  45. catch(Exception e){
  46. status.setText("Exception: " + e.getMessage());
  47. }
  48.  
  49. Intent myIntent(view.getContext(),AdminScreen.class);
  50. startActivity(myIntent);
Add Comment
Please, Sign In to add comment