Android Open Source - mpiwifi Wifi Login Service






From Project

Back to project page mpiwifi.

License

The source code is released under:

GNU General Public License

If you think the Android project mpiwifi 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.sorz.mpiwifi;
//  www  .  java 2  s  . c  o  m
import org.sorz.mpiwifi.exceptions.LoginFailException;

import android.app.IntentService;
import android.content.Intent;
import android.os.Handler;
import android.widget.Toast;

public class WifiLoginService extends IntentService {
  Handler mHandler;
  
  public WifiLoginService() {
    this("WifiLoginService");
  }

  public WifiLoginService(String name) {
    super(name);
    mHandler = new Handler();
  }

  @Override
  protected void onHandleIntent(Intent intent) {
    String username = intent.getStringExtra("username");
    String password = intent.getStringExtra("password");

    String ip = null;
    try {
      ip = WifiLoginer.login(username, password);
    } catch (LoginFailException e) {
      mHandler.post(new DisplayToast(R.string.err_loginFail));
    } catch (Exception e) {
      // Ignore
    }

    if (ip != null) {
      String msg = String.format(getString(R.string.login_ok), ip);
      mHandler.post(new DisplayToast(msg));
    }

  }

  private class DisplayToast implements Runnable {
    int mRID;
    String mText;

    public DisplayToast(int RID) {
      mRID = RID;
    }

    public DisplayToast(String text) {
      mText = text;
    }

    public void run() {
      if (mText == null)
        Toast.makeText(WifiLoginService.this, mRID, Toast.LENGTH_SHORT)
            .show();
      else
        Toast.makeText(WifiLoginService.this, mText, Toast.LENGTH_SHORT)
            .show();
    }
  }

}




Java Source Code List

org.sorz.mpiwifi.DNSResolver.java
org.sorz.mpiwifi.MainActivity.java
org.sorz.mpiwifi.NetworkBroadcast.java
org.sorz.mpiwifi.WifiLoginService.java
org.sorz.mpiwifi.WifiLoginer.java
org.sorz.mpiwifi.exceptions.AlreadyConnectedException.java
org.sorz.mpiwifi.exceptions.LoginFailException.java
org.sorz.mpiwifi.exceptions.NetworkException.java
org.sorz.mpiwifi.exceptions.NoNetworkAccessException.java
org.sorz.mpiwifi.exceptions.UnknownNetworkException.java