I am a beginner in android development, looking for how to make it verifiable code for server connection, ie if the user does not have a connection, and it connects to my server, in this case an error message will show "connection error" or nothing affair.
thank you for helping me :)
upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File f = new File(path);
Future uploading = Ion.with(MainActivity.this)
.load("http://x.x.x.x/upload_file") //->how to change this code for to verify the connection
.setMultipartFile("image",f)
//asJsonObject()
.asString()
.withResponse()
.setCallback(new FutureCallback<Response<String>>() {
@Override
public void onCompleted(Exception e, Response<String> result) {
try {
JSONObject jobj = new JSONObject(result.getResult());
Toast.makeText(getApplicationContext(), jobj.getString("response"), Toast.LENGTH_SHORT).show();
} catch (JSONException e1) {
e1.printStackTrace();
}
}
});
}
});