Skip to content

Instantly share code, notes, and snippets.

@sakshiagg1993
Created April 5, 2016 17:20
Show Gist options
  • Save sakshiagg1993/ff7b072161b3e1832cbbe458aff3535d to your computer and use it in GitHub Desktop.
Save sakshiagg1993/ff7b072161b3e1832cbbe458aff3535d to your computer and use it in GitHub Desktop.
package com.example.sakshi.offlinesecuritypage1;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
ProgressDialog mProgressDialog;
EditText EmailId, PhoneNumber;
Button Submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EmailId = (EditText) findViewById(R.id.editText6);
PhoneNumber = (EditText) findViewById(R.id.editText2);
Submit = (Button)findViewById(R.id.button);
Submit.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String emailid = " ", phonenumber = " ";
emailid = EmailId.getText().toString();
phonenumber = PhoneNumber.getText().toString();
String url;
url = "http://sakshi.byethost14.com/register2.php?email=" + emailid + "&phone=" + phonenumber;
url = url.replaceAll(" ", "%20");
Log.d("url", url);
new Checkemail().execute(url);
}
public class Checkemail extends AsyncTask<String, Void, Integer> {
@Override
protected void onPreExecute() {
mProgressDialog = new ProgressDialog(MainActivity.this);
// Set progressdialog title
mProgressDialog.setMessage("Verifying Email");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setCancelable(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Integer doInBackground(String... params) {
Integer result = 0;
HttpURLConnection urlConnection;
try {
URL url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
int statusCode = urlConnection.getResponseCode();
// 200 represents HTTP OK
if (statusCode == 200) {
BufferedReader r = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
response.append(line);
}
Log.d("str", response.toString());
checkemailfunction(response.toString());
result = 1; // Successful
} else {
result = 0; //"Failed to fetch data!";
}
} catch (Exception e) {
//Log.d(TAG, e.getLocalizedMessage());
}
return result; //"Failed to fetch data!";
}
@Override
protected void onPostExecute(Integer result) {
try {
if ((mProgressDialog != null) && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
} catch (final IllegalArgumentException e) {
// Handle or log or ignore
} catch (final Exception e) {
// Handle or log or ignore
} finally {
mProgressDialog = null;
}
if (result == 1) {
}
else {
Toast.makeText(MainActivity.this, "Failed to fetch data!", Toast.LENGTH_SHORT).show();
}
}
}
private void checkemailfunction(String result) {
try {
Log.d("this is result", result);
JSONObject jsonObject= new JSONObject(result);
String phonenumber = jsonObject.getString("phonenumber");
String emailid = jsonObject.getString("emailid");
} catch (JSONException e1) {
e1.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment