Android Open Source - cloudwave Connectivity Change Receiver

From Project

Back to project page cloudwave.


The source code is released under:

Apache License

If you think the Android project cloudwave listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.luboganev.cloudwave.receivers;
//from  ww  w .ja  v  a2 s  .  c om
import com.commonsware.cwac.wakeful.WakefulIntentService;
import com.luboganev.cloudwave.LogUtils;
import com.luboganev.cloudwave.service.ChangeWallpaperService;
import com.luboganev.cloudwave.service.CommunicationUtils;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

 * This broadcast receiver gets notified when network connectivity 
 * has changed. It is registered in the app's manifest but is not
 * enabled the whole time. It is being enabled when we want to get
 * some new sound wave image or other info from Soundcloud API, but 
 * there is currently no Internet connectivity. When the Internet 
 * connectivity is available again, it calls the execution of all 
 * the necessary work and disables itself again. 
public class ConnectivityChangeReceiver extends BroadcastReceiver {
  public void onReceive(Context context, Intent intent) {
    if(CommunicationUtils.hasInternetConnectivity(context)) {
      LogUtils.d(this, "OMG, there is internet! Better start working then.");
      // we have internet, have the change wallpaper service called
      Intent serviceIntent = new Intent(context, ChangeWallpaperService.class);
      WakefulIntentService.sendWakefulWork(context, serviceIntent);
      // disable this broadcastReceiver
      CommunicationUtils.setConnectivityChangeReceiverEnabled(context, false);

Java Source Code List