SHARE
TWEET

Untitled

a guest Dec 13th, 2016 171 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Context ctx;
  2. String method,userID,userName,password,postData,result;
  3.  
  4. MySqlDatabaseHelper(Context _ctx)
  5. {
  6.     ctx = _ctx;
  7. }
  8.  
  9. @Override
  10. protected void onPreExecute() {
  11.     super.onPreExecute();
  12. }
  13.  
  14. @Override
  15. protected String doInBackground(String... params) {
  16.     try {
  17.  
  18.         method = params[0].toString();
  19.  
  20.         if(method.equals("login"))
  21.         {
  22.             userName = params[1].toString();
  23.             password = params[2].toString();
  24.             URL url = new URL("http://10.0.2.2/Android/login.php");
  25.  
  26.             HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  27.             conn.setRequestMethod("POST");
  28.             conn.setDoInput(true);
  29.             conn.setDoInput(true);
  30.  
  31.             OutputStream os = conn.getOutputStream();
  32.             OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
  33.             BufferedWriter bw = new BufferedWriter(osw);
  34.  
  35.             postData = URLEncoder.encode("uname","UTF-8") + "=" + URLEncoder.encode(userName,"UTF-8") + "&" +
  36.                     URLEncoder.encode("password","UTF-8") + "=" + URLEncoder.encode(password,"UTF-8");
  37.  
  38.             bw.write(postData);
  39.  
  40.             bw.flush();
  41.             bw.close();
  42.             osw.close();
  43.             os.close();
  44.  
  45.             InputStream is = conn.getInputStream();
  46.             InputStreamReader isr = new InputStreamReader(is,"UTF-8");
  47.             BufferedReader br = new BufferedReader(isr);
  48.  
  49.             String line = "";
  50.             while ((line = br.readLine()) != null)
  51.             {
  52.                 result += line;
  53.             }
  54.  
  55.             br.close();
  56.             isr.close();
  57.             is.close();
  58.             conn.disconnect();
  59.             return result;
  60.         }
  61.         else
  62.         {
  63.             return "NONE";
  64.         }
  65.     }
  66.     catch (Exception ex)
  67.     {
  68.         Log.d("Err",ex.getMessage());
  69.         AlertDialog alert = new AlertDialog.Builder(ctx).create();
  70.         alert.setTitle("Something Went Wrong1");
  71.         alert.setMessage("-"+ex.getMessage()+"-");
  72.         alert.show();
  73.         return "ERR";
  74.     }
  75. }
  76.  
  77. @Override
  78. protected void onProgressUpdate(Void... values) {
  79.     super.onProgressUpdate(values);
  80. }
  81.  
  82. @Override
  83. protected void onPostExecute(String result) {
  84.     AlertDialog alert = new AlertDialog.Builder(ctx).create();
  85.     alert.setTitle("Successfully Worked");
  86.     alert.setMessage("-"+result+"-");
  87.     alert.show();
  88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top