Android Open Source - Fon Wifi Intent Receiver






From Project

Back to project page Fon.

License

The source code is released under:

GNU General Public License

If you think the Android project Fon 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 org.rsalvaterra.fon;
/* w  ww  . ja v  a2 s  . c om*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.preference.PreferenceManager;

public final class WifiIntentReceiver extends BroadcastReceiver {

  private static boolean isAutoConnectEnabled(final Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.key_autoconnect), true);
  }

  @Override
  public void onReceive(final Context context, final Intent intent) {
    final String action = intent.getAction();
    if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) && WifiIntentReceiver.isAutoConnectEnabled(context)) {
      context.startService(new Intent(context, IntentHandlingService.class).setAction(String.valueOf(Actions.ACTION_CONNECT)));
    } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
      final NetworkInfo ni = (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
      if ((ni.getType() == ConnectivityManager.TYPE_WIFI)) {
        if (ni.getState() == NetworkInfo.State.CONNECTED) {
          context.startService(new Intent(context, IntentHandlingService.class).setAction(String.valueOf(Actions.ACTION_LOGIN)));
        } else if (ni.getState() == NetworkInfo.State.DISCONNECTED) {
          context.startService(new Intent(context, IntentHandlingService.class).setAction(String.valueOf(Actions.ACTION_CANCEL_SCHEDULED_ACTIONS)));
        }
      }
    } else if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) && (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_DISABLED)) {
      context.startService(new Intent(context, IntentHandlingService.class).setAction(String.valueOf(Actions.ACTION_CANCEL_NOTIFICATION)));
    }
  }
}




Java Source Code List

org.rsalvaterra.fon.Actions.java
org.rsalvaterra.fon.HttpUtils.java
org.rsalvaterra.fon.IntentHandlingService.java
org.rsalvaterra.fon.ResponseCodes.java
org.rsalvaterra.fon.WifiIntentReceiver.java
org.rsalvaterra.fon.activity.AdvancedPreferences.java
org.rsalvaterra.fon.activity.BasicPreferences.java
org.rsalvaterra.fon.login.FonInfoHandler.java
org.rsalvaterra.fon.login.FonLogin.java
org.rsalvaterra.fon.login.FonResponseHandler.java
org.rsalvaterra.fon.login.LivedoorLogin.java
org.rsalvaterra.fon.login.LoginManager.java
org.rsalvaterra.fon.login.LoginResult.java
org.rsalvaterra.fon.login.SFRLogin.java