Question

I am trying to establish if a device has a connection to a particular site. If it does then it should start an intent, if it doesn't it should throw a toast.

It always seems to throw a toast though even if the device can see the site:-

public void GoToStation(View v)
{

    try {
        InetAddress ina = InetAddress.getByName("http://www.lisbury.co.uk");

        ina.isReachable(10000); {

                  Intent myIntent = new Intent(MainActivity.this, CustomizedListViewStation.class);
                  startActivityForResult(myIntent, 0);

        } 
    } catch (IOException ioe) {
        Toast.makeText(this, "You need a data connection to view Safety Zones", Toast.LENGTH_LONG).show();

    }    

 }

No correct solution

OTHER TIPS

 InetAddress ina = InetAddress.getByName("www.lisbury.co.uk");

but isReachable doesn't really guarantee that a device can connect to a site - isReachable is using ICMP echo and TCP to port 7, both can be filtered out, yet the host is available, and vice versa - the host can be available, but web server is down

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top