Issue
Hey guys i am new to Android networking concepts.I want to send username,password,imei number and location to the php server from android app.I am done my sending part.now my question is how to receive the response.i want to get the status (1 or 0) according to that i want to move to the next page.so anyone will know how to do this you are welcome.
private static final String REGISTER_URL="http://vPC70.com/App/login.php";
username = editTextUserName.getText().toString().toLowerCase();
userpassword=editTextPassword.getText().toString().toLowerCase();
loc="11.295756,77.001890";
imeino = "12312312456";
register(username, userpassword, imeino, loc);
private void register(final String username, final String userpassword,
String imeino, String loc) {
String urlSuffix = "?
username="+username+"&userpassword="+userpassword+"&imeino="+imeino
+"&location="+loc;
class RegisterUser extends AsyncTask<String,String , String>{
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(LoginActivity.this, "Please
Wait",null, true, true);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
}
@Override
protected String doInBackground(String... params) {
String s = params[0];
BufferedReader bufferedReader = null;
try {
URL url = new URL(REGISTER_URL+s);
HttpURLConnection con = (HttpURLConnection)
url.openConnection();
bufferedReader = new BufferedReader(new
InputStreamReader(con.getInputStream()));
String result;
result = bufferedReader.readLine();
return result;
}catch(Exception e){
return null;
}
}
}
RegisterUser ru = new RegisterUser();
ru.execute(urlSuffix);
this is the response
{"Login":[{"status":"1","message":"Login Successfully !!!"}]}
{"Login":[{"status":"0","message":"Invalid Password !!!"}]}
if the response is 1 toast the message login sucessfully if the response is 0 toast the message invalid password in post execute
Solution
After getting the response from server,based on status display the message in toast
try {
JSONObject jobj = new JSONObject(response);
String status = jobj.getString("status");
String msg = jobj.getString("message");
if (status.equals("1")) {
//move to next page
Toast.makeText(LoginActivity.this, msg,Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(LoginActivity.this, msg,Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
Answered By - Sunil P
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.