My application is working perfect in wifi and mobile networks, but fails to detect when connected through bluetooth tethering.
public boolean isNetworkAvailable() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
return false;
}
I tried running a few other applications . they also shows no network connectivity, But google applications works perfect and so as some other apps like whatsap. Wondering how they are doing it, and why most of the applications missing this point..
Can anyone tell me a way to check the internet connectivity in android, through all means available,including bluetooth pan and proxy,etc.
Any help will be appreciated. Thanks in advance..
To enable Bluetooth Tethering, go to Settings >> More >> Tethering & Portable hotspot >> select Bluetooth Tethering. The main challenge of Bluetooth tethering, like with USB tethering, is that it only supports one device at a time. That is the device that's connected to your Android via Bluetooth.
In the PAN, the internet connection of one of the devices can be shared with the other device through Bluetooth tethering. Using this Bluetooth technology, you can pair a payment terminal with an Android or iOS tablet or smartphone that functions as a mobile POS system.
PANS provides additional granularity of control specific to network traffic routing in Android. For example, OEMs can optimally define a logical network topology for the routing of application-level traffic.
Try connecting to an "always available" website. if any connection exist, this should return true:
protected static boolean hasInternetAccess()
{
try
{
URL url = new URL("http://www.google.com");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setRequestProperty("User-Agent", "Android Application:1");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(1000 * 30);
urlc.connect();
// http://www.w3.org/Protocols/HTTP/HTRESP.html
if (urlc.getResponseCode() == 200 || urlc.getResponseCode() > 400)
{
// Requested site is available
return true;
}
}
catch (Exception ex)
{
// Error while trying to connect
return false;
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With