I am using volley connection in local host and have a php file in the local host. Below is my class VolleyConnectionLogin and I have also a volley singleton class(which has no error)..
public class VolleyConnectionLogin {
Context context;
public VolleyConnectionLogin(Context context){
this.context = context;
}
static Boolean check;
public Boolean volleyConnection(final String username , final String password) {
String tag_string_req = "string_req";
String url = "http://192.168.10.8/login/forlogin.php";
StringRequest stringRequest = new StringRequest(Request.Method.POST,
url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
if(response.toString().equals("successful")){
check = true;
}else{
check = false;
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
check = false;
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("uname", username);
params.put("pword", password);
return params;
}
};
VolleySingleton.getInstance(context).addToRequestQueue(stringRequest);
return check;
}
}