Android Open Source - muwifi-autologin Network State Changed






From Project

Back to project page muwifi-autologin.

License

The source code is released under:

Copyright 2011-2014 Pawit Pornkitprasan. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are...

If you think the Android project muwifi-autologin 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.dyndns.pawitp.muwifiautologin;
//from ww  w. j  ava  2 s .  com
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.preference.PreferenceManager;
import android.util.Log;

public class NetworkStateChanged extends BroadcastReceiver {

    private static final String TAG = "NetworkStateChanged";
    private static final String[] SSID = {"MU-WiFi", "IC-WiFi"};

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive");
        // Check preference
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        if (!prefs.getBoolean(Preferences.KEY_ENABLED, false)) {
            // Disable the BroadcastReceiver so it isn't called in the future
            Utils.setEnableBroadcastReceiver(context, false);
            return;
        }

        // Check network connected
        NetworkInfo netInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        Log.d(TAG, "onReceive: netInfo = " + netInfo);
        if (!netInfo.isConnected()) {
            return;
        }

        // Check SSID
        String ssid = Utils.getSsid(context);
        Log.d(TAG, "ssid = " + ssid);
        boolean validSsid = false;
        for (String checkSsid : SSID) {
            if (checkSsid.equalsIgnoreCase(ssid) || ("\"" + checkSsid + "\"").equalsIgnoreCase(ssid)) {
                // JB 4.2 puts quote around SSID
                validSsid = true;
                break;
            }
        }
        if (!validSsid) {
            Log.d(TAG, "Invalid SSID");
            return;
        }

        Log.v(TAG, "Connected to the correct network");

        Intent i = new Intent(context, MuWifiLogin.class);
        context.startService(i);
    }

}




Java Source Code List

org.dyndns.pawitp.muwifiautologin.ArubaClient.java
org.dyndns.pawitp.muwifiautologin.CiscoClient.java
org.dyndns.pawitp.muwifiautologin.IcClient.java
org.dyndns.pawitp.muwifiautologin.LoginClient.java
org.dyndns.pawitp.muwifiautologin.LoginException.java
org.dyndns.pawitp.muwifiautologin.MuWifiLogin.java
org.dyndns.pawitp.muwifiautologin.MySSLSocketFactory.java
org.dyndns.pawitp.muwifiautologin.NetworkStateChanged.java
org.dyndns.pawitp.muwifiautologin.PostRetryHandler.java
org.dyndns.pawitp.muwifiautologin.Preferences.java
org.dyndns.pawitp.muwifiautologin.ShortcutActivity.java
org.dyndns.pawitp.muwifiautologin.Utils.java