I currently listen for changes in the Wi-Fi in my Android application and 
for the most part it works OK, however when the user has there device is 
idle/sleep mode, as in when the screen is blank. If they walk into a Wi-Fi 
area and automatically connect I don't get the intent until the user has 
turned on the screen. This is not good and leads to complaints about my 
application. Can anyone help with why I don't get the intent until the 
screen wakes up?

Here is my code:

BroadcastReciever:

    public class WifiReciever extends BroadcastReceiver{
        
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            
            String action = arg1.getAction();
    
            if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)){
                return;
            }                    
    
            if (!noConnectivity)
            {
                if (aNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI)
                {
                    //Handle connected case
                    Log.e("E", "GOT CONNECTION"); 
                }
            }
            else
            {
                if (aNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI)
                {
                    //Handle disconnected case
                    Log.e("E", "LOST CONNECTION");
                }
            }
            
        }

If a running Service I have that as a variable:

    WifiReciever mConnectionReceiver;


And I start and stop the receiver in the service with the following calls:

    private synchronized void startMonitoringConnection()
    {       
        IntentFilter aFilter = new 
IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);   
        registerReceiver(mConnectionReceiver, aFilter);
    }
    
    private synchronized void stopMonitoringConnection()
    {     
        unregisterReceiver(mConnectionReceiver);
    }

I call a WakeLock to make sure that I am getting CPU time like this:

    pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CicCPULock");
    wl.acquire();

However even with all that I never receive the Connectivity changed intent 
if the screen is blank, it works 100% of the time when the screen is on bit 
if I a user walks into a Wi-Fi are and connects when the screen is blank I 
fail to get the intent, is anyone aware of something I am missing?


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to