You are on page 1of 2

public void Sign_In(View view){

String email = em.getText().toString().trim();


String password = pas.getText().toString().trim();
if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password))
{
try {
String data = URLEncoder.encode("user_email", "UTF-8")
+ "=" + URLEncoder.encode(email, "UTF-8");

data += "&" + URLEncoder.encode("user_pass", "UTF-8") +


"="
+ URLEncoder.encode(password, "UTF-8");

URL url = new


URL("https://splick.aqtdemos.com/api/v1_user/authenticate");
HttpURLConnection conn = (HttpURLConnection)
url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);

OutputStreamWriter writer = new


OutputStreamWriter(conn.getOutputStream());
writer.write(data);
writer.flush();

BufferedReader in = new BufferedReader(new


InputStreamReader(
conn.getInputStream()));
String inputLine;
final StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {


response.append(inputLine);
}
in.close();
resp = response.toString();

JSONObject obj = new JSONObject(response.toString());


JSONObject status = obj.getJSONObject("success");
String success = status.getString("success");

Toast.makeText(getApplicationContext(),"Success :"+success,Toast.LENGTH_SHORT).show
();

/*
JSONObject dataObj = obj.getJSONObject("data");
String full_name = dataObj.getString("full_name");
String email_ = dataObj.getString("user_email");
String bio = dataObj.getString("user_bio");
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {

@Override
public void run() {

try {
// Toast.makeText(getApplicationContext(),
response.toString(), Toast.LENGTH_LONG).show();

JSONObject obj = new


JSONObject(response.toString());
JSONObject dataObj = obj.getJSONObject("data");
String daattaa =
dataObj.getString("full_name");
Toast.makeText(getApplicationContext(),
daattaa, Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
*/
conn.disconnect();
}
catch(Exception e){
e.printStackTrace();
}
}
else {
Toast.makeText(getApplicationContext(),"Please Enter Email
and Password",Toast.LENGTH_SHORT).show();
}

You might also like