Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Context ctx;
- String method,userID,userName,password,postData,result;
- MySqlDatabaseHelper(Context _ctx)
- {
- ctx = _ctx;
- }
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
- @Override
- protected String doInBackground(String... params) {
- try {
- method = params[0].toString();
- if(method.equals("login"))
- {
- userName = params[1].toString();
- password = params[2].toString();
- URL url = new URL("http://10.0.2.2/Android/login.php");
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setRequestMethod("POST");
- conn.setDoInput(true);
- conn.setDoInput(true);
- OutputStream os = conn.getOutputStream();
- OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
- BufferedWriter bw = new BufferedWriter(osw);
- postData = URLEncoder.encode("uname","UTF-8") + "=" + URLEncoder.encode(userName,"UTF-8") + "&" +
- URLEncoder.encode("password","UTF-8") + "=" + URLEncoder.encode(password,"UTF-8");
- bw.write(postData);
- bw.flush();
- bw.close();
- osw.close();
- os.close();
- InputStream is = conn.getInputStream();
- InputStreamReader isr = new InputStreamReader(is,"UTF-8");
- BufferedReader br = new BufferedReader(isr);
- String line = "";
- while ((line = br.readLine()) != null)
- {
- result += line;
- }
- br.close();
- isr.close();
- is.close();
- conn.disconnect();
- return result;
- }
- else
- {
- return "NONE";
- }
- }
- catch (Exception ex)
- {
- Log.d("Err",ex.getMessage());
- AlertDialog alert = new AlertDialog.Builder(ctx).create();
- alert.setTitle("Something Went Wrong1");
- alert.setMessage("-"+ex.getMessage()+"-");
- alert.show();
- return "ERR";
- }
- }
- @Override
- protected void onProgressUpdate(Void... values) {
- super.onProgressUpdate(values);
- }
- @Override
- protected void onPostExecute(String result) {
- AlertDialog alert = new AlertDialog.Builder(ctx).create();
- alert.setTitle("Successfully Worked");
- alert.setMessage("-"+result+"-");
- alert.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement