Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting connection returns false even when the device has connection

I have an app that has an alarmlistener that returns position and send it to a server, but firts it checks the internet connection. This is the method that checks the connection:

public boolean hasInternetConnection() {        
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager != null) {
            NetworkInfo networkInfo = connectivityManager
                    .getActiveNetworkInfo();            
            if (networkInfo != null && networkInfo.isAvailable()            
                    && networkInfo.isConnected()) {                     
                return true;
            } else {
                return false;                   
            }
        } else {
            return false;
        }
    }

Permissions on the Manifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="pe.com.hacom.taxitrack.mgr.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

And it has been working fine, but when I tried it on a Motorola XT316 it didn't work, it always return false, even when the device has connection, I check it openning the internet browser and it shows the webpage normally, but the alarm still returning false with that method.

I tested it in other devices and it works fine with all, but that Motorola, any idea what is happening? is that a hardware bug?

And the most rare thing is that sometimes I can get the device in DDMS for the logs on the debug but almost always it appears "Offline". I have installed the driver that is in the device, also uninstalling it and installing the universal driver of motorola from the webpage, and its working with Motoroal RAZR's but not with the XT316.

like image 785
Alejandro Cumpa Avatar asked Feb 15 '23 04:02

Alejandro Cumpa


1 Answers

This might be happening because the device have some sort of battery management system, which disables internet connection, and enables it when you open the browser, but it doesn't work when this Alarm is triggered.

like image 70
Reinherd Avatar answered Mar 05 '23 18:03

Reinherd