I'm working on an Android app and currently stuck to link my database to my app for registration using volley but I get the problem: this is response:
com.android.volley.NoConnectionError:java.io.IOEXCEPTION: Cleartext HTTP traffic to 10.0.2.2 not permitted
Here is my MainActivity code:
public class MainActivity extends AppCompatActivity {
Button loginBtn;
EditText password, username;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
password = findViewById(R.id.pssword);
username = findViewById(R.id.username);
loginBtn = findViewById(R.id.check);
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login();
}
});
}
void login() {
StringRequest request = new StringRequest(Request.Method.POST,
"http://10.0.2.2:80/android/test.php", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplicationContext(), "this is response: " + response,
Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "this is response: " + error,
Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("username", "hicham");
params.put("password", "hello");
return params;
}
};
Volley.newRequestQueue(this).add(request);
}
}