In my android app I have a button that when clicked, opens another class that makes a network call.
I am trying to check for a data connection when the button is clicked and if there isn't a connection I want to display a toast message.
Here is my onclick method as it stands:-
public void GoToZone(View v)
{
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Intent myIntent = new Intent(MainActivity.this, CustomizedListViewStudentZone.class);
startActivityForResult(myIntent, 0);
}
else {
Context context = getApplicationContext();
CharSequence text = "There seems to be a connection issue";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
How would I be able to check for a connection when the button is pressed and if there is a connection then proceed with the above and if there isn't then display a message saying "No Connection"
I am really struggling with implementing the check.
Thanks