I have a app but have teen testing it on an LG G4 i just started testing on other devices but with my samsung s9 the http requests/POST i make to receive JSON data from an API wont work i can not even log into the app
So i have tried to google answers and look on this site to see if there is a solution but tried a lot of them none that worked the message i get from the logcat is:
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
tried to google those messages but came up with the same results as previous i am using the Volley library to POST to the server
This is my LoginActivity.java:
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
final EditText username = findViewById(R.id.username);
final EditText password = findViewById(R.id.password);
final Button loginButton = findViewById(R.id.login_button);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String uName = username.getText().toString();
final String pWord = password.getText().toString();
Response.Listener<String> listener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Map<String, List<String>> map = new HashMap<>();
JSONObject jsonResponse = new JSONObject(response);
String success = jsonResponse.getString("sukses");
if (success.equals("true")) {
JSONObject jsonArray = jsonResponse.getJSONObject(uName);
JSONArray regions = jsonArray.names();
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < regions.length(); i++) {
String id = regions.getString(i);
list.add(regions.getString(i).toString());
JSONObject regionArray = jsonArray.getJSONObject(id);
JSONArray fields = regionArray.names();
List<String> fieldName = new ArrayList<>();
for (int d = 0; d < fields.length(); d++) {
String field = fields.getString(d);
fieldName.add(field);
}
map.put(id, fieldName);
}
Intent farms = new Intent(LoginActivity.this, FarmsActivity.class);
farms.putExtra("username", uName);
farms.putExtra("password", pWord);
farms.putExtra("list", list);
farms.putExtra("map", (Serializable) map);
startActivity(farms);
} else {
AlertDialog.Builder invalid = new AlertDialog.Builder(LoginActivity.this);
invalid.setTitle("Login Failed");
invalid.setMessage("Invalid Login Details")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e){
e.printStackTrace();
}
}
};
LoginRequest loginRequest = new LoginRequest(uName, pWord, listener);
loginRequest.setRetryPolicy(new DefaultRetryPolicy(
0,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
queue.add(loginRequest);
}
});
}
}
and this is the LoginRequest:
public class LoginRequest extends StringRequest{
private static final String LOGIN_REQUEST_URL = "MY HTML LINK";
private Map<String, String> params;
public LoginRequest(String username, String password, Response.Listener<String> listener) {
super(Request.Method.POST, LOGIN_REQUEST_URL, listener, null);
params = new HashMap<>();
params.put("username", username);
params.put("password", password);
}
@Override
public Map<String, String> getParams(){
return params;
}
}